-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcontent_entity_base.module
67 lines (61 loc) · 1.9 KB
/
content_entity_base.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @file
* Contains content_entity_base.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function content_entity_base_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the content_entity_base module.
case 'help.page.content_entity_base':
return t('<h3>@title</h3><p>@help_text</p>', [
'@title' => 'About',
'@help_text' => 'Provides base classes for bundle-able custom entities.',
]);
default:
return '';
}
}
/**
* Implements hook_theme_registry_alter.
*/
function content_entity_base_theme_registry_alter(&$theme_registry) {
// Check for entity_add_list which was added in 8.1.x.
if (!isset($theme_registry['entity_add_list'])) {
$theme_registry['entity_add_list'] = [
'variables' => [
'bundles' => [],
'bundle_type' => NULL,
'add_bundle_message' => NULL,
],
'template' => 'ceb-entity-add-list',
'path' => drupal_get_path('module', 'content_entity_base') . '/templates',
];
}
}
/**
* Prepares variables for the list of available bundles.
*
* Default template: entity-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - bundles: An array of bundles with the label, description, add_link keys.
* - add_bundle_message: The message shown when there are no bundles. Only
* available if the entity type uses bundle entities.
*/
function content_entity_base_preprocess_entity_add_list(&$variables) {
// Don't run this code in 8.1 or later, because
// \template_preprocess_entity_add_list does the same already.
if (version_compare(\Drupal::VERSION, '8.1') === 1) {
return;
}
foreach ($variables['bundles'] as $bundle_name => $bundle_info) {
$variables['bundles'][$bundle_name]['description'] = [
'#markup' => $bundle_info['description'],
];
}
}