-
Notifications
You must be signed in to change notification settings - Fork 4
/
iastate_theme.theme
243 lines (208 loc) · 10 KB
/
iastate_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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
use Drupal\node\NodeInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements template_preprocess_html().
*
*/
function iastate_theme_preprocess_html(&$variables) {
/* Add node-id_ and node-type_ classes to body */
$node = \Drupal::request()->attributes->get('node');
if ($node instanceof NodeInterface) {
$variables['attributes']['class'][] = 'node-id_' . $node->id();
}
if (isset($variables['node_type'])) {
$variables['attributes']['class'][] = 'node-type_' . $variables['node_type'];
}
/* Add views classes to body */
$route = \Drupal::routeMatch()->getRouteObject();
$view_id = $route->getDefault('view_id');
$display_id = $route->getDefault('display_id');
if ($view_id) {
$variables['attributes']['class'][] = 'view_' . $view_id;
$variables['attributes']['class'][] = 'view-display_' . $display_id;
}
}
/*
* Implements template_preprocess_menu_local_task().
*
* Add Bootstrap 4 classes to links in tabs
*/
function iastate_theme_preprocess_menu_local_task(&$variables) {
$variables['link']['#attributes']['class'][] = 'nav-link';
if (!empty($variables['element']['#active'])) {
$variables['link']['#attributes']['class'][] = 'active';
}
}
/*
* Implements template_preprocess_views_view().
*
* Add Bootstrap 4 classes to views buttons
*/
function iastate_theme_preprocess_views_view(&$variables) {
$variables['more']['#options']['attributes']['class'] = array('btn', 'btn-sm', 'btn-outline-danger');
}
/*
* Implements template_preprocess_menu_local_action().
*
* Add Bootstrap 4 classes to local actions
*/
function iastate_theme_preprocess_menu_local_action(&$variables) {
$variables['link']['#options']['attributes']['class'][] = 'btn';
$variables['link']['#options']['attributes']['class'][] = 'btn-sm';
$variables['link']['#options']['attributes']['class'][] = 'btn-outline-info';
}
/*
* Implements template_preprocess_links().
*
* Add Bootstrap 4 classes to Read More and Comments links
*/
function iastate_theme_preprocess_links(&$variables) {
if (!empty($variables['links']['node-readmore']['link'])) {
$variables['links']['node-readmore']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-danger';
}
if (!empty($variables['links']['comment-comments']['link'])) {
$variables['links']['comment-comments']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-danger';
}
if (!empty($variables['links']['comment-add']['link'])) {
$variables['links']['comment-add']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-success';
}
if (!empty($variables['links']['comment-delete']['link'])) {
$variables['links']['comment-delete']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-danger';
}
if (!empty($variables['links']['comment-edit']['link'])) {
$variables['links']['comment-edit']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-info';
}
if (!empty($variables['links']['comment-reply']['link'])) {
$variables['links']['comment-reply']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-success';
}
/* Book */
if (!empty($variables['links']['book_printer']['link'])) {
$variables['links']['book_printer']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-info';
}
if (!empty($variables['links']['book_add_child']['link'])) {
$variables['links']['book_add_child']['link']['#options']['attributes']['class'][] = 'btn btn-sm btn-outline-success';
}
}
/*
* Implements theme_form_alter().
*
* Add ISU Theme class to Site Navbar search form
*/
function iastate_theme_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if( $form_id == 'search_block_form') {
$form['actions']['submit']['#attributes']['class'][] = 'isu-search__search-btn';
}
}
/*
* Implements template_preprocess_field_multiple_value_form().
*
* Add Bootstrap 4 table classes to the multipe value field tables.
*/
function iastate_theme_preprocess_field_multiple_value_form(&$variables) {
$variables['table']['#attributes']['class'][] = 'table table-bordered isu-multiple-value-form-table';
if (!empty($variables['table']['#header'][0]['data']['#prefix']) && $variables['table']['#header'][0]['data']['#prefix'] == "<h4 class=\"label\">") {
unset($variables['table']['#header'][0]['data']['#prefix'], $variables['table']['#header'][0]['data']['#suffix']);
}
}
/*
* Implements template_preprocess_file_widget_multiple().
*
* Add Bootstrap 4 table classes to multiple file/image field tables.
*/
function iastate_theme_preprocess_file_widget_multiple(&$variables) {
$variables['table']['#attributes']['class'][] = 'table table-bordered isu-file-widget-multiple-table';
}
/*
* Implements theme_preprocess()
*
* Allow is_front to be used on other templates
*/
function iastate_theme_preprocess(&$variables, $hook) {
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
catch (Exception $e) {
$variables['is_front'] = FALSE;
}
// Ensure the cache varies correctly (new in Drupal 8.3).
$variables['#cache']['contexts'][] = 'url.path.is_front';
$variables['iastate_unit_name'] = theme_get_setting('iastate_unit_name');
$variables['iastate_unit_url'] = theme_get_setting('iastate_unit_url');
// Check to see if it's an edit/add/ or delete node page
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'entity.node.edit_form') {
$variables['is_node_edit'] = 'edit';
}
elseif ($route_name == 'node.add') {
$variables['is_node_add'] = 'add';
}
elseif ($route_name == 'entity.node.delete_form') {
$variables['is_node_delete'] = 'delete';
}
$variables['iastate_copyright_hidden'] = theme_get_setting('iastate_copyright_hidden');
}
/*
* Implements theme_preprocess_block().
*
*/
function iastate_theme_preprocess_block(&$variables) {
// Make theme settings available in block templates
$variables['iastate_logo_alt'] = theme_get_setting('iastate_logo_alt');
$variables['iastate_logo_width'] = theme_get_setting('iastate_logo_width');
$variables['iastate_logo_height'] = theme_get_setting('iastate_logo_height');
$variables['iastate_logo_alt'] = theme_get_setting('iastate_logo_alt');
$variables['is_default_logo'] = \Drupal::config('iastate_theme.settings')->get('logo.use_default');
$variables['iastate_logo_url'] = theme_get_setting('iastate_logo_url');
// Make block type available in block templates
if ($variables['elements']['#base_plugin_id'] == 'block_content') {
$blockType = strtr($variables['content']['#block_content']->bundle(), '_', '-');
$variables['attributes']['class'][] = 'block-type_' . $blockType;
}
}
/*
* Implements theme_preprocess_page().
*
* Make theme settings available in page templates
*/
function iastate_theme_preprocess_page(&$variables) {
$variables['isu_navbar'] = theme_get_setting('isu_navbar');
$variables['gold_border_hidden'] = theme_get_setting('gold_border_hidden');
$variables['theme_path'] = base_path() . $variables['directory'];
$variables['iastate_footer_logo_path'] = theme_get_setting('iastate_footer_logo_path');
$variables['iastate_footer_logo_url'] = theme_get_setting('iastate_footer_logo_url');
$variables['iastate_footer_logo_alt'] = theme_get_setting('iastate_footer_logo_alt');
$variables['iastate_footer_logo_width'] = theme_get_setting('iastate_footer_logo_width');
$variables['iastate_footer_logo_height'] = theme_get_setting('iastate_footer_logo_height');
$variables['iastate_contact_title'] = theme_get_setting('iastate_contact_title');
$variables['iastate_contact_address'] = theme_get_setting('iastate_contact_address');
$variables['iastate_contact_email'] = theme_get_setting('iastate_contact_email');
$variables['iastate_contact_phone'] = theme_get_setting('iastate_contact_phone');
$variables['iastate_contact_fax'] = theme_get_setting('iastate_contact_fax');
$variables['iastate_associate1_title'] = theme_get_setting('iastate_associate1_title');
$variables['iastate_associate1_url'] = theme_get_setting('iastate_associate1_url');
$variables['iastate_associate2_title'] = theme_get_setting('iastate_associate2_title');
$variables['iastate_associate2_url'] = theme_get_setting('iastate_associate2_url');
$variables['iastate_associate3_title'] = theme_get_setting('iastate_associate3_title');
$variables['iastate_associate3_url'] = theme_get_setting('iastate_associate3_url');
$variables['iastate_associate4_title'] = theme_get_setting('iastate_associate4_title');
$variables['iastate_associate4_url'] = theme_get_setting('iastate_associate4_url');
$variables['iastate_associate5_title'] = theme_get_setting('iastate_associate5_title');
$variables['iastate_associate5_url'] = theme_get_setting('iastate_associate5_url');
$variables['iastate_associate6_title'] = theme_get_setting('iastate_associate6_title');
$variables['iastate_associate6_url'] = theme_get_setting('iastate_associate6_url');
$variables['iastate_social1_title'] = theme_get_setting('iastate_social1_title');
$variables['iastate_social1_url'] = theme_get_setting('iastate_social1_url');
$variables['iastate_social2_title'] = theme_get_setting('iastate_social2_title');
$variables['iastate_social2_url'] = theme_get_setting('iastate_social2_url');
$variables['iastate_social3_title'] = theme_get_setting('iastate_social3_title');
$variables['iastate_social3_url'] = theme_get_setting('iastate_social3_url');
$variables['iastate_social4_title'] = theme_get_setting('iastate_social4_title');
$variables['iastate_social4_url'] = theme_get_setting('iastate_social4_url');
$variables['iastate_social5_title'] = theme_get_setting('iastate_social5_title');
$variables['iastate_social5_url'] = theme_get_setting('iastate_social5_url');
$variables['iastate_social6_title'] = theme_get_setting('iastate_social6_title');
$variables['iastate_social6_url'] = theme_get_setting('iastate_social6_url');
$variables['iastate_social7_title'] = theme_get_setting('iastate_social7_title');
$variables['iastate_social7_url'] = theme_get_setting('iastate_social7_url');
}