Newer
Older
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
<?php
/**
* @file
* Functions to support theming in the wcm8_theme theme.
*/
/**
* Adds additional theme settings.
*/
function wcm8_theme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
$form['theme_customization'] = array (
'#type' => 'fieldset',
'#title' => t('Theme Customization'),
'#markup' => t('Customize the look and feel of the site.')
);
$form['theme_customization']['header'] = array(
'#type' => 'fieldset',
'#title' => t('Header')
);
$navbar_color_options = [
'light' => t('Light'),
'dark' => t('Dark')
];
$form['theme_customization']['header']['osu_navbar_color'] = array(
'#type' => 'radios',
'#title' => t('OSU Navbar Color'),
'#default_value' => theme_get_setting('osu_navbar_color'),
'#options' => $navbar_color_options
);
$masthead_variant_options = [
'standard' => t('Standard'),
'slim' => t('Slim')
];
$form['theme_customization']['header']['masthead_variant'] = array(
'#type' => 'radios',
'#title' => t('Masthead Variant'),
'#default_value' => theme_get_setting('masthead_variant'),
'#options' => $masthead_variant_options
);
$masthead_color_options = [
'dk-gray' => t('Dark Gray'),
'md-gray' => t('Medium Gray'),
'lt-gray' => t('Light Gray'),
'white' => t('White')
];
$form['theme_customization']['header']['masthead_color'] = array(
'#type' => 'radios',
'#title' => t('Masthead Color'),
'#default_value' => theme_get_setting('masthead_color'),
'#options' => $masthead_color_options
);
$form['theme_customization']['footer'] = array(
'#type' => 'fieldset',
'#title' => t('Footer')
);
$footer_color_options = [
'dk-gray' => t('Dark Gray'),
'md-gray' => t('Medium Gray'),
'lt-gray' => t('Light Gray'),
'white' => t('White')
];
$form['theme_customization']['footer']['footer_color'] = array(
'#type' => 'radios',
'#title' => t('Footer Color'),
'#default_value' => theme_get_setting('footer_color'),
'#options' => $footer_color_options
);
}
/**
* Clear caches when settings change.
*/
function wcm8_theme_settings_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
drupal_flush_all_caches();
}
/**
* Implements hook_preprocess().
*/
function wcm8_theme_preprocess(array &$variables, $hook) {
//all-purpose variables
$variables['base_path'] = base_path();
//theme setting variables
$variables['osu_navbar_color'] = theme_get_setting('osu_navbar_color');
$variables['masthead_variant'] = theme_get_setting('masthead_variant');
$variables['masthead_color'] = theme_get_setting('masthead_color');
$variables['footer_color'] = theme_get_setting('footer_color');
// Load the site name out of configuration.
$config = \Drupal::config('system.site');
$variables['site_name'] = $config->get('name');
// Load variables from Site Information module.
$siteinfo_config = \Drupal::config('wcm8_siteinfo.settings');
$siteinfo_vars = [
'site_name_prefix',
'admin_link',
'footer_text',
'address_1',
'address_2',
'city',
'state',
'zip',
'phone',
'fax',
'contact_email',
'ada_email',
'twitter',
'facebook',
'linkedin',
'youtube',
'instagram',
'photos'
];
foreach ($siteinfo_vars as $siteinfo_var) {
$variables[$siteinfo_var] = $siteinfo_config->get($siteinfo_var);
}
}
/**
* Implements hook_preprocess_html().
*/
function wcm8_theme_preprocess_html(array &$variables) {
// Add footer color to body classes.
$variables['attributes']['class'][] = 'footer-color--' . theme_get_setting('footer_color');
// Add node id to body classes.
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$node = \Drupal::routeMatch()->getParameter('node');
$variables['attributes']['class'][] = 'nid--' . $node->id();
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
}
}
/**
* Implements hook_preprocess_page().
*/
function wcm8_theme_preprocess_page(&$variables) {
$variables['site_name'] = \Drupal::config('system.site')->get('name');
}
/**
* Implements hook_theme_suggestions_alter().
*/
function wcm8_theme_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$content_type = $node->bundle();
}
if ($hook == 'form' & !empty($variables['element']['#id'])) {
$suggestions[] = 'form__' . str_replace('-', '_', $variables['element']['#id']);
}
if ($hook == 'details' & !empty($variables['element']['#id'])) {
$suggestions[] = 'details__'. $content_type;
}
}
/**
* Implements hook_theme_suggestions_block_alter().
*/
function wcm8_theme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (isset($variables['elements']['content']['#block_content'])) {
array_splice($suggestions, 1, 0, 'block__' . $variables['elements']['content']['#block_content']->bundle());
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function wcm8_theme_preprocess_details(array &$variables, $hook) {
if ($node = \Drupal::request()->attributes->get('node')) {
$variables['nid'] = $node->id();
}
}