-
Notifications
You must be signed in to change notification settings - Fork 4
/
hdbt_subtheme.theme
55 lines (48 loc) · 1.61 KB
/
hdbt_subtheme.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
49
50
51
52
53
54
55
<?php
/**
* @file
* Functions to support theming in the HDBT Subtheme.
*/
declare(strict_types=1);
/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_subtheme_preprocess_block(&$variables) {
if (isset($variables['elements']['#id'])) {
$variables['content']['#attributes']['block_id'] = $variables['elements']['#id'];
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function hdbt_subtheme_theme_suggestions_block_alter(&$suggestions) {
// Load theme suggestions for blocks from parent theme.
foreach ($suggestions as &$suggestion) {
$suggestion = str_replace('hdbt_subtheme_', '', $suggestion);
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function hdbt_subtheme_theme_suggestions_menu_alter(&$suggestions, $variables) {
if (isset($variables['attributes']['block_id'])) {
$block_id = str_replace('hdbt_subtheme_', '', $variables['attributes']['block_id']);
$suggestions[] = match ($block_id) {
'mobile_navigation' => 'menu__mobile',
'mainnavigation' => 'menu__main__desktop',
'main_navigation_level_2' => 'menu__main__sidebar',
'brandingnavigation' => 'menu__main__branding',
default => 'menu__' . $variables['attributes']['block_id'],
};
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_subtheme_preprocess_menu(&$variables): void {
// Menu, mobile menu, fallback menu and sidebar menu tree depth.
// Counting from "instance", "main level", "level 3", "level 4", "level 5"...
$menu_depth = 6;
$variables['menu_depth'] = $menu_depth;
$variables['#attached']['drupalSettings']['menu_depth'] = $menu_depth;
}