forked from mgomma/d8theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d8theme.theme
executable file
·205 lines (173 loc) · 5.85 KB
/
d8theme.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
<?php
/**
* @file
* Functions to support theming in the d8theme theme.
*/
/**
* IMplememnts HOOK_preprocess().
* define global variables in all templates
*/
function d8theme_preprocess(&$variables, $hook, $info) {
// Add the Drupal globals variable.
$language = Drupal::languageManager()->getCurrentLanguage();
$variables['lang'] = $language->getId();
}
/**
* HOOK_theme_suggestions_block_alter().
*/
function d8theme_theme_suggestions_block_alter(array &$suggestions, array $variables)
{
// $block = $variables['elements'];
// $blockType = $block['#configuration']['provider'];
// if ($blockType == "block_content") {
// $bundle = $block['content']['#block_content']->bundle();
// $suggestions[] = 'block__' . $blockType . '__' . $bundle;
// }
}
/**
* Implements hook_preprocess_HOOK() for html.html.twig.
*/
function d8theme_preprocess_html(array &$variables) {
/* Add class to html tag */
//$variables['html_attributes']->addClass('no-js');
// Don't display the site name twice on the front page (and potentially others)
/*if (isset($variables['head_title_array']['title']) && isset($variables['head_title_array']['name']) && ($variables['head_title_array']['title'] == $variables['head_title_array']['name'])) {
$variables['head_title'] = $variables['head_title_array']['name'];
}*/
}
/**
* Implements hook_page_attachments_alter().
*/
function d8theme_page_attachments_alter(array &$page) {
//add
$language = Drupal::languageManager()->getCurrentLanguage();
$lang_css = $language->getId() == 'en' ? 'en-css' : 'ar-css';
$page['#attached']['library'][] = 'd8theme/'.$lang_css;
// Tell IE to use latest rendering engine (not to use compatibility mode).
/*$ie_edge = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge',
],
];
$page['#attached']['html_head'][] = [$ie_edge, 'ie_edge'];*/
}
/**
* Implements hook_preprocess_page() for page.html.twig.
*/
function d8theme_preprocess_page(array &$variables) {
}
function d8theme_preprocess_pager(array &$variables) {
}
/**
* Implements hook_theme_suggestions_page_alter().
*/
function d8theme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_theme_suggestions_node_alter().
*/
function d8theme_theme_suggestions_node_alter(array &$suggestions, array $variables) {
/*$node = $variables['elements']['#node'];
if ($variables['elements']['#view_mode'] == "full") {
}*/
}
/**
* Implements hook_preprocess_HOOK() for Block document templates.
*/
function d8theme_preprocess_block(array &$variables) {
}
/**
* Add more suggestions to forms and form elements.
*/
function d8theme_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
$route_title = str_replace(' ', NULL, strtolower(\Drupal::request()->attributes->get('_title')));
if($hook == 'form'){
if(isset($variables['element']['#attributes'])){
$suggestions[] = 'form__'.str_replace('-', NULL, $variables['element']['#attributes']['data-drupal-selector']);
}
}else if($hook == 'form_element'){
$suggestions[] = 'form__element__'.$route_title.$variables['element']['#type'];
}else if($hook == 'input' || $hook == 'textarea'){
$suggestions[] = 'form__'.$route_title.$variables['element']['#type'];
if($variables['element']['#type'] == 'textfield'){
if(!isset($variables['element']['#attributes'])){
//add title as placeholder
$variables['element']['#attributes']['placeholder'] = isset($variables['element']['#title']) ? $variables['element']['#title']->render() : NULL;
}
}
}
}
/**
* Implements hook_theme_suggestions_field_alter().
*/
function d8theme_theme_suggestions_field_alter(array &$suggestions, array $variables) {
/*$element = $variables['element'];
$suggestions[] = 'field__' . $element['#view_mode'];
$suggestions[] = 'field__' . $element['#view_mode'] . '__' . $element['#field_name'];*/
}
/**
* Implements hook_theme_suggestions_field_alter().
*/
function d8theme_theme_suggestions_fieldset_alter(array &$suggestions, array $variables) {
/*$element = $variables['element'];
if (isset($element['#attributes']['class']) && in_array('form-composite', $element['#attributes']['class'])) {
$suggestions[] = 'fieldset__form_composite';
}*/
}
/**
* Implements hook_preprocess_node().
*/
function d8theme_preprocess_node(array &$variables) {
// Default to turning off byline/submitted.
//$variables['display_submitted'] = FALSE;
}
/**
* Implements hook_theme_suggestions_views_view_alter().
*/
function d8theme_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_preprocess_form().
*/
function d8theme_preprocess_form(array &$variables) {
//$variables['attributes']['novalidate'] = 'novalidate';
}
/**
* Implements hook_preprocess_select().
*/
function d8theme_preprocess_select(array &$variables) {
//$variables['attributes']['class'][] = 'select-chosen';
}
/**
* Implements hook_preprocess_select().
*/
function d8theme_preprocess_input(array &$variables) {
}
/**
* Implements hook_preprocess_field().
*/
function d8theme_preprocess_field(array &$variables, $hook) {
/*switch ($variables['element']['#field_name']) {
}*/
}
/**
* Implements hook_preprocess_details().
*/
function d8theme_preprocess_details(array &$variables) {
/*$variables['attributes']['class'][] = 'details';
$variables['summary_attributes']['class'] = 'summary';*/
}
/**
* Implements hook_theme_suggestions_details_alter().
*/
function d8theme_theme_suggestions_details_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_preprocess_menu_local_task().
*/
function d8theme_preprocess_menu_local_task(array &$variables) {
//$variables['element']['#link']['url']->setOption('attributes', ['class'=>'rounded']);
}