forked from localgovdrupal/localgov_subsites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalgov_subsites.module
69 lines (62 loc) · 1.55 KB
/
localgov_subsites.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
68
69
<?php
/**
* @file
* LocalGov Subsites module file.
*/
use Drupal\localgov_subsites\Subsite;
use Drupal\node\NodeInterface;
/**
* Implements hook_theme().
*/
function localgov_subsites_theme($existing, $type, $theme, $path) {
return [
'subsite_navigation' => [
'variables' => [
'menu_name' => '',
'items' => [],
'current_entity' => NULL,
'overview_entity' => NULL,
],
],
'subsite_banner' => [
'variables' => [
'tag' => '',
'heading' => '',
'image' => '',
],
],
'subsite_overview_banner' => [
'variables' => [
'heading' => '',
'image' => '',
],
],
'node__localgov_subsites_page__full' => [
'template' => 'node--localgov-subsites-page--full',
'base hook' => 'node',
],
];
}
/**
* Implements hook_preprocess_page().
*
* Adds a class to the page wrapper with the name of the theme
* if the current node is within a subsite.
*/
function localgov_subsites_preprocess_page(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if (!$node instanceof NodeInterface) {
return;
}
if (in_array($node->bundle(), [
'localgov_subsites_overview',
'localgov_subsites_page',
])) {
$subsite = \Drupal::service('class_resolver')
->getInstanceFromDefinition(Subsite::class)
->getSubsite($node);
if ($subsite instanceof NodeInterface && $theme = $subsite->localgov_subsites_theme->value) {
$variables['attributes']['class'][] = str_replace('_', '--', $theme);
}
}
}