-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-settings.php
143 lines (124 loc) · 4.03 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
<?php
/**
* @file
* Functions to support Centarro Claro theme settings.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter() for system_theme_settings.
*/
function centarro_claro_form_system_theme_settings_alter(&$form, FormStateInterface $form_state, $form_id = NULL)
{
$form['#attached']['library'][] = 'centarro_claro/color-picker';
// @TODO: Replace this
// \Drupal::service('theme.manager')->getActiveTheme()
$colors = [
'centarro_claro_primary_color' => 'Primary color',
'centarro_claro_focus_color' => 'Focus color',
];
$color_themes = [
'default' => [
'label' => 'Centarro Purple',
'colors' => [
'centarro_claro_primary_color' => '#4b4e9f',
'centarro_claro_focus_color' => '#ffa827',
],
],
'b&w' => [
'label' => 'Black and White',
'colors' => [
'centarro_claro_primary_color' => '#000000',
'centarro_claro_focus_color' => '#000000',
],
],
];
$form['#attached']['drupalSettings']['centarroClaro']['colorSchemes'] = $color_themes;
// General "alters" use a form id. Settings should not be set here. The only
// thing useful about this is if you need to alter the form for the running
// theme and *not* the theme setting.
// @see http://drupal.org/node/943212
if (isset($form_id)) {
return;
}
// Change collapsible fieldsets (now details) to default #open => FALSE.
$form['theme_settings']['#open'] = FALSE;
$form['logo']['#open'] = FALSE;
$form['favicon']['#open'] = FALSE;
// Utilitie details wrapper
$form['centarro_claro_utilities'] = [
'#type' => 'details',
'#title' => t('Centarro Claro Utilities'),
'#weight' => -10,
'#collapsible' => TRUE,
'#open' => TRUE,
];
// Colors
$form['centarro_claro_utilities']['centarro_claro_enable_color'] = [
'#type' => 'checkbox',
'#title' => t('Enable color Scheme'),
'#default_value' => theme_get_setting('centarro_claro_enable_color'),
'#ajax' => [
'callback' => 'centarroColorCallback',
'wrapper' => 'color_container',
],
];
$form['centarro_claro_utilities']['color_container'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'color_container'
],
];
if ($form_state->getValue('centarro_claro_enable_color', theme_get_setting('centarro_claro_enable_color'))) {
$form['centarro_claro_utilities']['color_container']['centarro_claro_color_scheme'] = [
'#type' => 'select',
'#title' => t('Default Color Scheme'),
'#empty_option' => t('Custom'),
'#empty_value' => '',
'#options' => [
'default' => t('Default'),
'b&w' => t('Black and White'),
],
'#input' => FALSE,
'#wrapper_attributes' => [
'style' => 'display:none;',
],
];
foreach ($colors as $key => $title) {
$form['centarro_claro_utilities']['color_container'][$key] = [
'#type' => 'textfield',
'#maxlength' => 7,
'#size' => 10,
'#title' => t($title),
'#description' => t('Enter color in full hexadecimal format (#abc123).') . '<br/>' . t('Derivatives will be formed from this color.'),
'#default_value' => theme_get_setting($key),
'#attributes' => [
'pattern' => '^#[a-fA-F0-9]{6}',
],
'#wrapper_attributes' => [
'data-drupal-selector' => 'centarro-claro-color-picker',
],
];
}
}
// Fonts/theme size
$form['centarro_claro_utilities']['theme_size'] = [
'#type' => 'select',
'#title' => t('Theme size:'),
'#options' => [
'default' => t('Default (Claro)'),
'medium' => t('Medium'),
'compact' => t('Compact'),
],
'#description' => ('This changes the root font size and resizes all theme elements.'),
'#default_value' => theme_get_setting('theme_size'),
];
// Other.
}
/**
* @param $form
* @param FormStateInterface $form_state
* @return mixed
*/
function centarroColorCallback($form, FormStateInterface $form_state) {
return $form['centarro_claro_utilities']['color_container'];
}