-
Notifications
You must be signed in to change notification settings - Fork 2
/
twbase_utils.module
172 lines (159 loc) · 5.6 KB
/
twbase_utils.module
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
<?php
/**
* @file
* TWBase Theme utilities module.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Utility function that return the current theme name.
*
* @return string
* The current theme name.
*/
function _twbase_utils_get_default_theme() {
return \Drupal::service('theme_handler')->getDefault();
}
/**
* Utility function that indicates if twbase is a base theme.
*
* @return boolean
* Return TRUE if the current theme is a sub theme of TWBase, FALSE otherwise.
*/
function _twbase_utils_is_basetheme() {
// Get default theme name
$default_theme = \Drupal::service('theme_handler')->getDefault();
// Get a list of currently installed themes
$list_info = \Drupal::service('theme_handler')->listInfo();
// Finds all the base themes for the default theme
$base_themes = \Drupal::service('theme_handler')->getBaseThemes($list_info, $default_theme);
// Return a boolean that indicates if twbase is a base theme
return isset($base_themes['twbase']);
}
/**
* Implements hook_node_editor_js_settings_alter().
*/
function twbase_utils_editor_js_settings_alter(array &$settings) {
if(_twbase_utils_get_default_theme() !== 'twbase' && !_twbase_utils_is_basetheme() ) {
return;
}
foreach (array_keys($settings['editor']['formats']) as $text_format_id) {
if ($settings['editor']['formats'][$text_format_id]['editor'] === 'ckeditor') {
// Add the necessary class to the WYSIWYG editor, so that the it matches the front end.
// Necessary to make tailwindcss-typography works in admin/ckeditor
// See: https://www.drupal.org/project/drupal/issues/2674412
$settings['editor']['formats'][$text_format_id]['editorSettings']['bodyClass'] = "tw-p-4 tw-prose";
// kint($settings['editor']['formats'][$text_format_id]['editorSettings']);
// $settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'] = [];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Lead",
'element' => "p",
'attributes' => [
'class' => "lead"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Code",
'element' => "code",
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Text primary",
'element' => "span",
'attributes' => [
'class' => "text-primary"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Text secondary",
'element' => "span",
'attributes' => [
'class' => "text-secondary"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Text success",
'element' => "span",
'attributes' => [
'class' => "text-success"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Text danger",
'element' => "span",
'attributes' => [
'class' => "text-danger"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Text warning",
'element' => "span",
'attributes' => [
'class' => "text-warning"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button",
'element' => "a",
'attributes' => [
'class' => "button"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button primary",
'element' => "a",
'attributes' => [
'class' => "button button--primary"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button secondary",
'element' => "a",
'attributes' => [
'class' => "button button--secondary"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button success",
'element' => "a",
'attributes' => [
'class' => "button button--success"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button danger",
'element' => "a",
'attributes' => [
'class' => "button button--danger"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button warning",
'element' => "a",
'attributes' => [
'class' => "button button--warning"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Button info",
'element' => "a",
'attributes' => [
'class' => "button button--info"
]
];
$settings['editor']['formats'][$text_format_id]['editorSettings']['stylesSet'][] = [
'name' => "Dropcap",
'element' => "span",
'attributes' => [
'class' => "dropcap"
]
];
}
}
}
/**
* Implements hook_form_FORM_ID_alter() for node_type_form().
*/
function twbase_utils_form_node_type_form_alter(array &$form, FormStateInterface $form_state) {
// Load the real code only when needed.
\Drupal::moduleHandler()->loadInclude('twbase_utils', 'inc', 'twbase_utils.admin');
_twbase_utils_form_node_type_form_alter($form, $form_state);
}