-
Notifications
You must be signed in to change notification settings - Fork 1
/
localgov_base_croydon.theme
190 lines (155 loc) · 6.98 KB
/
localgov_base_croydon.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* @file
* Theme hooks to support the LocalGov Base Croydon theme.
*/
/**
* Implements hook_preprocess_block() for hook_preprocess_block__localgov_base_croydon_subsitebanner_homepage().
*
* Makes the render array for the *banner image path* available to the block
* template.
*/
function localgov_base_croydon_preprocess_block__localgov_base_croydon_subsitebanner_homepage(&$variables) {
$banner_paragraph = $variables['content']['#paragraph'];
$has_no_banner_img = !($banner_paragraph->localgov_image and $banner_paragraph->localgov_image->count());
if ($has_no_banner_img) {
$variables['banner_img_url'] = '';
return;
}
$banner_img = $banner_paragraph->localgov_image->entity;
$banner_img_url = Drupal::service('entity_type.manager')->getViewBuilder($banner_img->getEntityTypeId())->view($banner_img, 'cds_image_path');
$variables['banner_img_url'] = $banner_img_url;
}
/**
* Implements hook_preprocess_node() for hook_preprocess_node__localgov_guides_page().
*
* - Sets Guide page content width.
*/
function localgov_base_croydon_preprocess_node__localgov_guides_overview__full(&$variables) {
$variables['attributes']['class'][] = 'lgd-row__two-thirds';
}
/**
* Implements hook_preprocess_node() for hook_preprocess_node__localgov_guides_page().
*
* - Sets Guide page content width.
*/
function localgov_base_croydon_preprocess_node__localgov_guides_page__full(&$variables) {
$variables['attributes']['class'][] = 'lgd-row__two-thirds';
}
/**
* Hides label from "Plain address" view mode of Geo.
*/
function localgov_base_croydon_preprocess_geo_entity__cds_plain_address(&$variables) {
$variables['content']['label'] = NULL;
}
/**
* See above.
*/
function localgov_base_croydon_preprocess_localgov_geo__cds_plain_address(&$variables) {
localgov_base_croydon_preprocess_geo_entity__cds_plain_address($variables);
}
/**
* Implements hook_preprocess_paragraph().
*
* Changes:
* Adds a variable to determinse if the box links are
* on the home page.
*
* @see localgov_base_croydon_preprocess_paragraph__localgov_box_link()
*/
function localgov_base_croydon_preprocess_paragraph__localgov_box_link(&$variables) {
$paragraph = $variables['paragraph'];
if ($paragraph->bundle() === 'localgov_box_link') {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
}
/**
* Prepares variables for webform submission data templates.
*/
function localgov_base_croydon_preprocess_webform_submission_data(array &$variables) {
// Completed Form.
$completed_form = [];
$completed_form = $variables["elements"]["data"];
foreach ($completed_form as $page_key => $page_value) {
// Are the elelemnts on a wizard page?
// Set up the array keys.
// - Wizard page key.
// - Webfom element key.
if (isset($page_value["#value"]['#children'])) {
$webform_element_key = array_key_first($page_value["#value"]['#children']);
}
if (isset($page_value['#element']['#webform_key'])) {
$webform_wizard_page_key = $page_value['#element']['#webform_key'];
}
// Page title.
$webform_wizard_page_title = $page_value['#element']['#title'];
// Form Data - Label.
// Webform wizard page link.
// The Edit summary button.
if (isset($page_value["#value"]['#children']) && array_key_exists('wizard_page_link', $page_value["#value"]['#children'])) {
$webform_wizard_page_link = $page_value["#value"]['#children']['wizard_page_link'];
}
// Filter out Form elements
// Get the webform elements.
// Anything in the array that is not preceded with a '#'
// we assume is a webform element.
$webform_element = [];
$webform_element_value = NULL;
foreach (array_keys($page_value['#element']) as $element_setting_key => $element_setting_value) {
if("#" !== substr($element_setting_value, 0, 1)) {
$webform_element[$element_setting_value]['label'] = $page_value['#element'][$element_setting_value]['#title'];
$webform_element[$element_setting_value]['value'] = $page_value['#value']['#children'][$element_setting_value]['#value'];
}
// Check that the webform element's value is not empty
// If it's empty remove the element.
if ($webform_element[$element_setting_value]['value'] == null ) {
unset($webform_element[$element_setting_value]);
}
// Check if the webform element has a key called 'actions'.
// The 'action' array key will be the form submit button.
if (array_key_exists('actions', $webform_element)) {
unset($webform_element['actions']);
}
$webform_element_value = $webform_element;
}
// Check if this is a fieldset that has form elements in it.
// Form Data - Fieldset.
$webform_fieldset_element = [];
$webform_fieldset_element = NULL;
if (isset($webform_element_value[$webform_element_key]['value']["#type"]) &&
$webform_element_value[$webform_element_key]['value']['#type'] == 'fieldset' &&
$webform_element_value[$webform_element_key]['value']['#children'] != NULL ) {
$webform_fieldset_element = [];
// Fieldset label
if (isset($webform_element_value['value']) && $webform_element_value['value'] != NULL ) {
foreach ($webform_element_value['value']['#children'] as $element_key => $element_value) {
$webform_fieldset_element[$element_key]['fieldset_label'] = $webform_element['title'];
$webform_fieldset_element[$element_key]['label'] = $element_value['#element']['#title'];
$webform_fieldset_element[$element_key]['value'] = $element_value['#value'];
// Copy Webform fieldset element.
$webform_element_value = $webform_fieldset_element;
}
}
}
$completed_form[$page_key]['#summary']['page_key'] = $webform_wizard_page_key;
$completed_form[$page_key]['#summary']['page_title'] = $webform_wizard_page_title;
// $completed_form[$page_key]['#summary']['label'] = $webform_element_label;
$completed_form[$page_key]['#summary']['value'] = $webform_element_value;
$completed_form[$page_key]['#summary']['wizard_page_link'] = $webform_wizard_page_link;
}
$variables["elements"]["data"] = $completed_form;
}
/** * Implements hook_preprocess_hook() for hook_preprocess_node__cds_tenancy_office_dir_page__cds_definition_list.
*
* Provides localgov_location twice. This is for ease of styling the
* location map.
*/
function localgov_base_croydon_preprocess_node__cds_tenancy_office_dir_page__cds_definition_list(&$variables) {
if (isset($variables['content']['localgov_location'])) {
$variables['content']['localgov_location_copy'] = $variables['content']['localgov_location'];
}
if (isset($variables['content']['localgov_location']['#third_party_settings']['field_formatter_class'])) {
$variables['content']['localgov_location']['#third_party_settings']['field_formatter_class']['class'] .= ' localgov_location_original';
$variables['content']['localgov_location_copy']['#third_party_settings']['field_formatter_class']['class'] .= ' localgov_location_copy';
}
}