-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.php
392 lines (339 loc) · 13.3 KB
/
template.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
/**
* Override or insert variables into the html template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered. This is usually "html", but can
* also be "maintenance_page" since adie_preprocess_maintenance_page() calls
* this function to have consistent variables.
*/
function adie_preprocess_html(&$variables, $hook) {
// Add variables and paths needed for HTML5 and responsive support.
$variables['add_responsive_meta'] = TRUE;
// Attributes for html element.
$variables['html_attributes_array'] = array(
'lang' => $variables['language']->language,
'dir' => $variables['language']->dir,
'class' => array('no-js'),
);
}
/**
* Override or insert variables into the html templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("html" in this case.)
*/
function adie_process_html(&$variables, $hook) {
// Flatten out html_attributes.
$variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']);
}
/**
* Override or insert variables into the page template.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("page" in this case.)
*/
function adie_preprocess_page(&$variables, $hook) {
$main_menu = menu_tree_all_data('main-menu');
$variables['main_menu'] = menu_tree_output($main_menu);
// add a variable for debugging,
// like showing all region containers even if they have no content
//$variables['debug'] = FALSE;
// remove default message from main content if there is no content created yet.
//unset($variables['page']['content']['system_main']['default_message']);
}
/**
* Override or insert variables into the page template.
*
* @param $variables
* An array of variables to pass to the theme template.
*/
function adie_process_page(&$variables) {
// Since the title and the shortcut link are both block level elements,
// positioning them next to each other is much simpler with a wrapper div.
if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
// Add a wrapper div using the title_prefix and title_suffix render elements.
$variables['title_prefix']['shortcut_wrapper'] = array(
'#markup' => '<div class="shortcut-wrapper clearfix">',
'#weight' => 100,
);
$variables['title_suffix']['shortcut_wrapper'] = array(
'#markup' => '</div>',
'#weight' => -99,
);
// Make sure the shortcut link is the first item in title_suffix.
$variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
}
}
/**
* Override or insert variables into the node templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*/
function adie_preprocess_node(&$variables, $hook) {
// Add a suggestion based on view_mode.
$variables['theme_hook_suggestions'][] = 'node__' . $variables['view_mode'];
$variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];
// Add a class based on view_mode.
$variables['classes_array'][] = 'node-' . drupal_html_class($variables['view_mode']);
$variables['classes_array'][] = 'node-' . drupal_html_class($variables['type']) . '-' . drupal_html_class($variables['view_mode']);
// Add $unpublished variable.
$variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE;
// Add pubdate to submitted variable.
$variables['pubdate'] = '<time pubdate datetime="' . format_date($variables['node']->created, 'custom', 'c') . '">' . $variables['date'] . '</time>';
if ($variables['display_submitted']) {
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['pubdate']));
}
$variables['title_attributes_array']['class'][] = 'node-title';
}
/**
* Override or insert variables into the comment templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("comment" in this case.)
*/
function adie_preprocess_comment(&$variables, $hook) {
// If comment subjects are disabled, don't display them.
if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) {
$variables['title'] = '';
}
// Add pubdate to submitted variable.
$variables['pubdate'] = '<time pubdate datetime="' . format_date($variables['comment']->created, 'custom', 'c') . '">' . $variables['created'] . '</time>';
$variables['submitted'] = t('!username commented on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['pubdate']));
// Zebra striping.
if ($variables['id'] == 1) {
$variables['classes_array'][] = 'first';
}
if ($variables['id'] == $variables['node']->comment_count) {
$variables['classes_array'][] = 'last';
}
$variables['classes_array'][] = $variables['zebra'];
$variables['title_attributes_array']['class'][] = 'comment-title';
}
/**
* Override or insert variables into the taxonomy term templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function adie_preprocess_taxonomy_term(&$variables) {
// Add a suggestion based on view_mode.
$variables['theme_hook_suggestions'][] = 'term__' . $variables['view_mode'];
$variables['theme_hook_suggestions'][] = 'term__' . $variables['vocabulary_machine_name'] . '__' . $variables['view_mode'];
// Add a class based on view_mode.
$variables['classes_array'][] = 'term-' . drupal_html_class($variables['view_mode']);
$variables['classes_array'][] = 'term-' . drupal_html_class($variables['vocabulary_machine_name']) . '-' . drupal_html_class($variables['view_mode']);
$variables['title_attributes_array']['class'][] = 'term-title';
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function adie_preprocess_block(&$variables, $hook) {
$variables['classes_array'][] = $variables['block_zebra'];
$variables['title_attributes_array']['class'][] = 'block-title';
// Add Aria Roles via attributes.
// Suggest a navigation block template if appropriate.
switch ($variables['block']->module) {
case 'admin':
switch ($variables['block']->delta) {
case 'menu':
// Suggest a navigation block template and set role
$variables['theme_hook_suggestions'][] = 'block__navigation';
$variables['attributes_array']['role'] = 'navigation';
break;
}
break;
case 'system':
switch ($variables['block']->delta) {
case 'main':
// Note: the "main" role goes in the page.tpl, not here.
// Use a template with no wrapper for the page's main content.
$variables['theme_hook_suggestions'][] = 'block__no_wrapper';
break;
case 'help':
case 'powered-by':
$variables['attributes_array']['role'] = 'complementary';
break;
default:
// Any other "system" block is a menu block.
$variables['theme_hook_suggestions'][] = 'block__navigation';
$variables['attributes_array']['role'] = 'navigation';
break;
}
break;
case 'menu':
// add a class indicating the menu name
$variables['classes_array'][] = drupal_html_class($variables['block']->delta);
case 'menu_block':
case 'blog':
case 'book':
case 'comment':
case 'forum':
case 'shortcut':
case 'statistics':
$variables['theme_hook_suggestions'][] = 'block__navigation';
$variables['attributes_array']['role'] = 'navigation';
break;
case 'search':
$variables['attributes_array']['role'] = 'search';
break;
case 'help':
case 'aggregator':
case 'locale':
case 'poll':
case 'profile':
$variables['attributes_array']['role'] = 'complementary';
break;
case 'node':
switch ($variables['block']->delta) {
case 'syndicate':
$variables['attributes_array']['role'] = 'complementary';
break;
case 'recent':
$variables['theme_hook_suggestions'][] = 'block__navigation';
$variables['attributes_array']['role'] = 'navigation';
break;
}
break;
case 'user':
switch ($variables['block']->delta) {
case 'login':
$variables['attributes_array']['role'] = 'form';
break;
case 'new':
case 'online':
$variables['attributes_array']['role'] = 'complementary';
break;
}
break;
case 'views':
// Add view css classes to block
if (isset($variables['elements']['#views_contextual_links_info']['views_ui']['view']->display['default']->display_options['css_class'])) {
$views_css_classes = explode(' ', $variables['elements']['#views_contextual_links_info']['views_ui']['view']->display['default']->display_options['css_class']);
$variables['classes_array'] = array_merge($variables['classes_array'], $views_css_classes);
}
break;
}
// In some regions, visually hide the title of any block, but leave it accessible.
$region = $variables['block']->region;
if ($region == 'header' ||
$region == 'navigation' ||
$region == 'highlighted') {
$variables['title_attributes_array']['class'][] = ' ';
}
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function adie_process_block(&$variables, $hook) {
// Drupal 7 should use a $title variable instead of $block->subject.
$variables['title'] = $variables['block']->subject;
}
/**
* Add some template suggestions
*
* @param $variables
* An array of variables to pass to the theme template.
*/
function adie_preprocess_panels_pane(&$variables) {
$subtype = $variables['pane']->subtype;
$layout = $variables['display']->layout;
$variables['theme_hook_suggestions'][] = 'panels_pane__' . $layout;
$variables['theme_hook_suggestions'][] = 'panels_pane__' . $subtype;
$variables['theme_hook_suggestions'][] = 'panels_pane__' . $layout . '__' . $subtype;
}
/**
* Implements hook_css_alter().
*/
function adie_css_alter(&$css) {
// Remove Drupal default stylesheets
$exclude = array(
'modules/system/system.base.css' => FALSE,
'modules/system/system.menus.css' => FALSE,
'modules/system/system.messages.css' => FALSE,
'modules/comment/comment.css' => FALSE,
'modules/node/node.css' => FALSE,
// jQuery UI
'misc/ui/jquery.ui.core.css' => FALSE,
'misc/ui/jquery.ui.theme.css' => FALSE,
'misc/ui/jquery.ui.tabs.css' => FALSE,
);
$css = array_diff_key($css, $exclude);
// remove some contrib stylesheets
$fuzzy_exclude = array('twocol.css', 'ds_2col_stacked.css', 'panels.css');
foreach ($css as $path => $meta) {
foreach ($fuzzy_exclude as $css_file) {
if (strpos($path, $css_file) !== FALSE) {
unset($css[$path]);
}
}
}
}
/**
* Overrides theme_menu_tree().
*/
function adie_menu_tree__main_menu($variables) {
// Add a class to main menu. This will be overridden for child menus
// by the next function.
return '<ul class="dropdown menu menu-responsive" data-dropdown-menu>' . $variables['tree'] . '</ul>';
}
function adie_menu_tree__menu_menu_ministere($variables) {
// Add a class to main menu. This will be overridden for child menus
// by the next function.
return '<ul class="menu vertical">' . $variables['tree'] . '</ul>';
}
/**
* A custom wrapper overrides theme_menu_tree() yet again, but only for
* child menus. This wrapper is declared in adie_menu_link__main_menu().
*/
function adie_menu_tree__main_menu__children($variables) {
// Add a 'dropdown' class to a child menu's <ul> element.
return '<ul class="menu vertical">' . $variables['tree'] . '</ul>';
}
/**
* Overrides theme_menu_link().
*/
function adie_menu_link__main_menu($variables){
$element = $variables['element'];
$sub_menu = '';
// Perform operations on list items with child menus.
if ($element['#below']) {
// Add 'has-dropdown' class to list item.
$element['#attributes']['class'][] = 'has-dropdown';
// Declare a new theme wrapper for this list item's child menu.
$element['#below']['#theme_wrappers'][0] = 'menu_tree__main_menu__children';
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
function adie_form_edit_name_alter(&$form, &$form_state, $form_id) {
if ($form['#form_id'] === 'edit-name') {
$form_structure = &$form['submitted'];
$form['actions']['submit']['#prefix'] = '<div class="extra_div">';
$form['actions']['submit']['#suffix'] = '</div>';
}
}