-
Notifications
You must be signed in to change notification settings - Fork 2
/
oddbaby.suggestions.inc
100 lines (84 loc) · 3.01 KB
/
oddbaby.suggestions.inc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
use Drupal;
/**
* @file
* This file contains additional theme suggestions added by the theme.
*/
/**
* Adds theme suggestions for field templates.
*
* Implements hook_theme_suggestions_HOOK().
*/
function oddbaby_theme_suggestions_field_alter(array &$suggestions, array $variables): void {
$element = $variables['element'];
// Add the view mode to the field theme suggestion.
if (isset($element['#view_mode'])) {
$suggestions[] = implode('__', [
'field',
$element['#entity_type'],
$element['#field_name'],
$element['#bundle'],
$element['#view_mode'],
]);
}
}
/**
* Adds theme suggestions for the page title based on the current route.
*
* Implements hook_theme_suggestions_HOOK_alter().
*/
function oddbaby_theme_suggestions_page_title_alter(array &$suggestions): void {
$path_args = [''];
if (!Drupal::service('path.matcher')->isFrontPage()) {
$path_args = explode('/', ltrim(Drupal::service('path.current')->getPath(), '/'));
}
$page_title_suggestions = theme_get_suggestions($path_args, 'page_title');
$suggestions = array_merge($suggestions, $page_title_suggestions);
}
/**
* Adds theme suggestions for taxonomy term templates.
*
* Implements hook_theme_suggestions_HOOK().
*/
function oddbaby_theme_suggestions_taxonomy_term_alter(array &$suggestions, array $variables): void {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $variables['elements']['#taxonomy_term'];
$view_mode = $variables['elements']['#view_mode'];
// Add theme suggestions for taxonomy terms.
$suggestions[] = 'taxonomy_term__' . $view_mode;
$suggestions[] = 'taxonomy_term__' . $term->bundle() . '__' . $view_mode;
}
/**
* Adds theme suggestions for view templates.
*
* Implements hook_theme_suggestions_HOOK_alter().
*/
function oddbaby_theme_suggestions_views_view_alter(array &$suggestions, array $variables): void {
/** @var \Drupal\views\ViewExecutable $view_executable */
$view_executable = $variables['view'];
// Add theme suggestions for taxonomy terms.
$suggestions[] = 'views_view__' . $view_executable->id();
$suggestions[] = 'views_view__' . $view_executable->id() . '__' . $view_executable->current_display;
}
/**
* Adds theme suggestions for the unformatted view template.
*
* Implements hook_theme_suggestions_HOOK_alter().
*/
function oddbaby_theme_suggestions_views_view_unformatted_alter(array &$suggestions, array $variables): void {
/** @var \Drupal\views\ViewExecutable $view */
$view = $variables['view'];
$suggestions[] = 'views_view_unformatted__' . $view->id();
$suggestions[] = 'views_view_unformatted__' . $view->id() . '__' . $view->current_display;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function oddbaby_theme_suggestions_user_alter(array &$suggestions, array $variables): void {
$element = $variables['elements'];
// Add a theme suggestion to the user template with the view mode.
if (isset($element['#view_mode'])) {
$suggestions[] = 'user__' . $element['#view_mode'];
}
}