-
Notifications
You must be signed in to change notification settings - Fork 2
/
csgov_theme.theme
100 lines (86 loc) · 3.04 KB
/
csgov_theme.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
<?php
declare(strict_types = 1);
use Drupal\Core\Entity\ContentEntityInterface;
use \Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
/**
* @file
* Functions to support theming.
*/
/**
* Implements hook_preprocess_image_widget().
*/
function csgov_theme_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 hook_preprocess_HOOK().
*/
function csgov_theme_preprocess_block(&$variables): void {
// Set block_id variable.
if (isset($variables['elements']['#id'])) {
$variables['content']['#attributes']['block_id'] = $variables['elements']['#id'];
}
// Handle Page title block.
if ($variables['plugin_id'] == 'page_title_block') {
$page_entity = csgov_base_get_page_entity();
if ($page_entity instanceof ContentEntityInterface) {
// Retrieve possible overridden value for page title block.
// Hide page title block if current node has hero set.
if (
$page_entity instanceof NodeInterface &&
$page_entity->hasField('field_csgov_hero') &&
$page_entity->hasField('field_csgov_has_hero') &&
$page_entity->get('field_csgov_has_hero')->value &&
!$page_entity->get('field_csgov_hero')->isEmpty()
) {
$variables['hide_block'] = TRUE;
}
}
}
}
/**
* Implements hook_preprocess_HOOK() for page templates.
*/
function csgov_theme_preprocess_page(&$variables) {
// Print the Installation Profile version.
// Get the name of the current installation profile.
$profile_name = \Drupal::installProfile();
// Load the profile using the extension list service.
$profile = \Drupal::service('extension.list.profile')->get($profile_name);
$variables['install_profile_name'] = $profile_name;
// Check if the profile object was loaded and get the info.
if ($profile) {
$info = $profile->info;
// Check if version is set and add it to the variables.
if (isset($info['version'])) {
$variables['install_profile_version'] = $info['version'];
} else {
$variables['install_profile_version'] = FALSE;
}
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function csgov_theme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (isset($variables['elements']['#configuration']['webform_id']) && $variables['elements']['#configuration']['webform_id']) {
$suggestions[] = 'block__webform__' . $variables['elements']['#configuration']['webform_id'];
}
}
/**
* Implements hook_form_alter().
*/
function csgov_theme_form_alter(&$form, $form_state, $form_id) {
// Add a library to all webforms.
if (isset($form['#webform_id'])) {
$form['#attached']['library'][] = 'csgov_theme/webform';
}
}