-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspTheme.theme
92 lines (84 loc) · 2.85 KB
/
aspTheme.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
<?php
/**
* @file
* Functions to support theming.
*/
use Drupal\Core\Render\Markup;
/**
* Implements hook_preprocess_html() for block templates.
*/
function aspTheme_preprocess_html(&$variables) {
$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];
}
}
/**
* Implements hook_preprocess_image_widget().
*/
function aspTheme_preprocess_image_widget(array &$variables) {
$data = &$variables['data'];
// This prevents image widget templates from rendering preview container HTML
// to users that do not have permission to access these previews.
// @todo revisit in https://drupal.org/node/953034
// @todo revisit in https://drupal.org/node/3114318
if (isset($data['preview']['#access']) && $data['preview']['#access'] === FALSE) {
unset($data['preview']);
}
}
/**
* Implements template_preprocess_image().
*/
function aspTheme_preprocess_image(&$variables) {
// Check the image style.
if ($variables['style_name'] == 'img_fluid') {
// Set class.
$variables['attributes']['class'][] = 'img-fluid';
}
}
/**
* Implements template_preprocess_field().
*/
function aspTheme_preprocess_field(&$variables) {
$node = $variables['element']['#object'];
if ($node->bundle() == 'affinity_group' || $node->bundle() == 'access_news') {
if ($variables['field_name'] == 'field_tags') {
foreach ($variables['items'] as $key => $item) {
$tag_classes = ['inline-block', 'font-normal', 'no-underline', 'px-2', 'py-1', 'hover--border-dark-teal', 'border', 'leading-tight', 'whitespace-nowrap'];
$variables['items'][$key]['content']['#attributes']['class'] = $tag_classes;
}
}
if ($variables['field_name'] == 'field_image') {
foreach ($variables['items'] as $key => $item) {
$classes = ['object-contain', 'm-0', 'h-auto'];
$variables['items'][$key]['content']['#item_attributes']['class'] = $classes;
}
}
}
}
/**
* Add classes to tag field for CI Links.
*/
function aspTheme_preprocess_views_view_field__webform_submission_value_8(&$variables) {
if ($variables['output']) {
$output = $variables['output'];
}
else {
return;
}
if ($output == ' ') {
return;
}
$tag_classes = 'inline-block font-normal border border-solid border-black px-2 py-1 no-underline me-2 mb-2 hover--border-dark-teal';
// Parse the $output string to get the links and add classes to them.
$new_output = '';
$dom = new DOMDocument();
$dom->loadHTML($output);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link) {
$link->setAttribute('class', $tag_classes);
$new_output .= $dom->saveHTML($link);
}
$variables['output'] = Markup::create($new_output);
}