-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrise.theme
48 lines (44 loc) · 1.46 KB
/
crise.theme
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
<?php
/**
* @file
* Bootstrap sub-theme.
*
* Place your custom PHP code in this file.
*/
function crise_theme_suggestions_input_alter(&$suggestions, array $variables) {
$element = $variables['element'];
if (isset($element['#attributes']['data-twig-suggestion'])) {
$suggestion_suffix = str_replace(['-'], '_', $element['#attributes']['data-twig-suggestion']);
$suggestions[] = 'input__' . $element['#type'] . '__' . $suggestion_suffix;
}
}
/**
* Implements template_preprocess_page().
*/
function crise_preprocess_page(&$variables) {
$entities = [];
foreach (\Drupal::routeMatch()->getParameters() as $param) {
if ($param instanceof \Drupal\Core\Entity\EntityInterface) {
$entities[] = $param;
}
}
$variables['crise_flags'] = array();
if ($entities) {
$entity = $entities[0];
// Get all possible flags for this entity type.
$flag_service = \Drupal::service('flag');
$flags = $flag_service->getAllFlags($entity->getEntityTypeID(), $entity->bundle());
foreach ($flags as $flag) {
$flag_type_plugin = $flag->getFlagTypePlugin();
$flag_link = $flag
->getLinkTypePlugin()
->getAsLink($flag, $entity);
$flag_url = $flag_link->getUrl();
$variables['crise_flags']["flag_{$flag->id()}"] = array(
'#title' => $flag_link->getText(),
'#type' => 'link',
'#url' => \Drupal\Core\Url::fromRoute($flag_url->getRouteName(), $flag_url->getRouteParameters()),
);
}
}
}