-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme-settings.php
150 lines (134 loc) · 4.79 KB
/
theme-settings.php
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
<?php
/**
* @file
* Add custom theme settings to the IU Framework theme.
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_system_theme_settings_alter().
*/
function iu_form_system_theme_settings_alter(&$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['breadcrumbs'] = [
'#type' => 'details',
'#title' => t('Breadcrumb'),
'#open' => TRUE,
];
$form['breadcrumbs']['hide_home_breadcrumb'] = [
'#type' => 'radios',
'#options' => [
'0' => t('Show %home in breadcrumb trail (Drupal’s default behavior)', ['%home' => 'Home']),
'1' => t('Remove %home from breadcrumb trail', ['%home' => 'Home']),
'2' => t('Remove %home when it is the only breadcrumb in trail', ['%home' => 'Home']),
],
'#default_value' => theme_get_setting('hide_home_breadcrumb'),
];
$form['branding_bar'] = [
'#type' => 'details',
'#title' => t('Branding bar'),
'#open' => TRUE,
'#description' => '<p>' . t('Specify which campus should be linked in the header.') . '</p>',
];
$form['branding_bar']['campus'] = [
'#type' => 'radios',
'#options' => [
'iu' => 'Indiana University (iu.edu)',
'iub' => 'IU Bloomington (indiana.edu)',
'iue' => 'IU East (iue.edu)',
'iuk' => 'IU Kokomo (iuk.edu)',
'iun' => 'IU Northwest (iun.edu)',
'iupui' => 'IUPUI (iupui.edu)',
'ius' => 'IU Southeast (ius.edu)',
'iusb' => 'IU South Bend (iusb.edu)',
'iufw' => 'IU Fort Wayne (iufw.edu)',
'iupuc' => 'IUPUC (iupuc.edu)',
],
'#description' => t('The header branding bar features the Block IU in a red bar and goes at the top of every page of your website. Each campus has its own branding bar, but only the name and link change.'),
'#default_value' => theme_get_setting('campus'),
];
$form['off_canvas'] = [
'#type' => 'details',
'#title' => t('Mobile menu position'),
'#open' => TRUE,
];
$off_canvas_position = theme_get_setting('off_canvas_position') ?: 'right';
$form['off_canvas']['off_canvas_position'] = [
'#type' => 'radios',
'#options' => [
'right' => t('Slide in from right side (IU Framework’s default behavior)'),
'left' => t('Slide in from left side'),
],
'#default_value' => $off_canvas_position,
];
$colors = _iu_secondary_color_palette_options();
$options = [];
foreach ($colors as $key => $color) {
$options[$key] = '
<div class="color-block ' . $color['class'] . '">
<div class="color-name">' . $color['name'] . '</div>
<div class="color-details">HEX: ' . $color['hex'] . '</div>
</div>
';
}
$form['color_palette'] = [
'#type' => 'details',
'#title' => t('Color palette'),
'#open' => TRUE,
];
$form['color_palette']['secondary_color'] = [
'#type' => 'radios',
'#title' => t('Secondary background color (for sections)'),
'#options' => $options,
'#attributes' => ['class' => ['color-block-radios']],
'#default_value' => theme_get_setting('secondary_color'),
'#description' => t('In addition to the two primary background colors (crimson and light gray) available for use in your site sections, you may also select one additional secondary background color from the expanded IU Color Palette. Note: Crimson is Indiana University’s main brand color and should always be used in greater frequency than any secondary color.'),
'#attached' => ['library' => ['iu/color-block']],
];
$form['#validate'][] = 'iu_form_system_theme_settings_validate';
$form['#submit'][] = 'iu_form_system_theme_settings_submit';
}
/**
* Form vallidation handler for system_theme_settings form.
*/
function iu_form_system_theme_settings_validate($form, FormStateInterface $form_state) {
// Set a flag to indicate whether caches need to be cleared.
$flush_caches = FALSE;
$settings = [
[
'branding_bar',
'campus',
],
[
'color_palette',
'secondary_color',
],
[
'off_canvas',
'off_canvas_position',
],
];
foreach ($settings as $setting) {
$original_value = NestedArray::getValue($form, array_merge($setting, ['#default_value']), $key_exists);
if ($key_exists) {
$submitted_value = $form_state->getValue(array_pop($setting));
if ($submitted_value !== $original_value) {
$flush_caches = TRUE;
break;
}
}
}
$form_state->set('flush_caches', $flush_caches);
}
/**
* Form submission handler for system_theme_settings form.
*/
function iu_form_system_theme_settings_submit($form, FormStateInterface $form_state) {
// Clear cached data so a change will take effect.
if ($form_state->get('flush_caches')) {
drupal_flush_all_caches();
}
}