-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdingo.theme
139 lines (126 loc) · 4.52 KB
/
dingo.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @file
* Functions to support theming.
*/
use Drupal\Component\Utility\Xss;
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*/
function dingo_preprocess_html(&$variables) {
// Add icon to title per environment.
$getEnv = \Drupal::service('oit.environment.icon');
$stack = \Drupal::request();
$keys = $stack->get('keys');
$env = getenv('AH_SITE_ENVIRONMENT');
// Currently used for login button via js injector to fix behat.
if ($env == 'local' || $env == 'LANDO') {
$variables['attributes']['class'][] = 'env-local';
}
if (isset($keys)) {
$searchKeys = Xss::filter($keys);
$searchKeys = strtolower($searchKeys);
$searchKeys = preg_replace("/(\W)+/", "", $searchKeys);
$variables['attributes']['class'][] = $searchKeys;
}
$path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $path);
if (isset($path_args[1]) && isset($path_args[2]) && ($path_args[1] == 'node') && (is_numeric($path_args[2]))) {
$variables['attributes']['class'][] = 'page-node-' . $path_args[2];
}
$current_title = $variables['head_title']['title'];
if (($variables['node_type'] ?? '') == 'webform' && isset($path_args[4])) {
$tempstore = \Drupal::service('tempstore.private')->get('servicenow');
$meow_status = $tempstore->get("meow-status");
// Add webform status to the page title for screen readers.
if ($path_args[4] == 'confirmation') {
if ($meow_status) {
$current_title = t('Successfully submitted -') . $current_title;
}
if ($meow_status === 0) {
$current_title = t('There was and error communicating with service now - ') . $current_title;
}
}
}
// Add icons to local/dev/test environments.
$variables['head_title']['title'] = $getEnv->getEnv() . $current_title;
}
/**
* Implements hook_preprocess_page_title() for HTML document templates.
*/
function dingo_preprocess_page_title(&$variables) {
$node = \Drupal::request()->attributes->get('node');
if (!is_string($node) && isset($node)) {
if ($node->bundle() == 'page') {
$title_image_fid = $node->get('field_title_background')->target_id;
if (isset($title_image_fid)) {
$file = \Drupal\file\Entity\File::load($title_image_fid);
$path = $file->getFileUri();
$url = $file->createFileUrl();
$variables['attributes'] = [
'data-bg-image' => $url,
];
}
}
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for form templates.
*/
function dingo_theme_suggestions_form_alter(array &$suggestions, array $variables) {
if ($variables['element']['#form_id'] == 'search_block_form') {
$suggestions[] = 'form__search_block_form';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for form element templates.
*/
function dingo_theme_suggestions_form_element_alter(array &$suggestions, array $variables) {
if ($variables['element']['#type'] == 'search') {
$suggestions[] = 'form_element__search_block_form';
}
}
/**
* Implements hook_preprocess_page().
*/
function dingo_preprocess_page(&$variables) {
$variables['#attached']['drupalSettings']['responsive_menu']['custom'] = [
'options' => [
'navbar' => [
'add' => TRUE,
'title' => 'Main Menu',
],
],
'config' => [
'classNames' => [
'selected' => 'menu-item--active-trail',
],
],
];
}
function dingo_preprocess_breadcrumb(&$variables) {
if(($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']){
$variables['#cache']['contexts'][] = 'url';
}
}
function dingo_preprocess_facets_result_item(&$variables) {
$facet = $variables['facet'];
$term_id = $variables['raw_value'];
if($facet->getFieldIdentifier() == 'field_oda_population' ||
$facet->getFieldIdentifier() == 'field_oda_level_of_detail' ||
$facet->getFieldIdentifier() == 'field_oda_cu_stats' ||
$facet->getFieldIdentifier() == 'field_oda_course_data' ||
$facet->getFieldIdentifier() == 'field_oda_term' ||
$facet->getFieldIdentifier() == 'field_oda_type' ||
$facet->getFieldIdentifier() == 'field_oda_academic_terms_covered' ||
$facet->getFieldIdentifier() == 'field_oda_demographics' ||
$facet->getFieldIdentifier() == 'field_oda_peers_ext_org'
) {
if ( \Drupal\taxonomy\Entity\Term::load($term_id) ) {
$term_description = \Drupal\taxonomy\Entity\Term::load($term_id)->get('description')->value;
}
}
if(isset($term_description)) {
$variables['term_description'] = rtrim(strip_tags($term_description));
}
}