1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* All Process functions for templates and theme fucntions.
|
6
|
*
|
7
|
* If you need to add or modify process functions do it in your sub-theme.
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Process variables for html.tpl.php
|
12
|
*/
|
13
|
function adaptivetheme_process_html(&$vars) {
|
14
|
// Flatten attributes arrays
|
15
|
$vars['html_attributes'] = empty($vars['html_attributes_array']) ? '' : drupal_attributes($vars['html_attributes_array']);
|
16
|
|
17
|
// $rdf_namespaces is kept to maintain backwards compatibility, and because we
|
18
|
// only want this to print once in html.tpl.php, and not in every conditional
|
19
|
// comment for IE.
|
20
|
$vars['rdf_namespaces'] = empty($vars['rdf_namespaces_array']) ? '' : drupal_attributes($vars['rdf_namespaces_array']);
|
21
|
|
22
|
// Render polyfills
|
23
|
if ($vars['polyfills']) {
|
24
|
$vars['polyfills'] = drupal_render($vars['polyfills']);
|
25
|
}
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Process variables for the html tag
|
30
|
*/
|
31
|
/* Deprecate due to: https://www.drupal.org/node/2312157, I don't think we really need to do this for html5.
|
32
|
function adaptivetheme_process_html_tag(&$vars) {
|
33
|
$tag = &$vars['element'];
|
34
|
if ($tag['#tag'] === 'style' || $tag['#tag'] === 'script') {
|
35
|
// Remove redundant type attribute and CDATA comments.
|
36
|
unset($tag['#attributes']['type'], $tag['#value_prefix'], $tag['#value_suffix']);
|
37
|
// Remove media="all" but leave others unaffected.
|
38
|
if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') {
|
39
|
unset($tag['#attributes']['media']);
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
*/
|
44
|
|
45
|
/**
|
46
|
* Process variables for page.tpl.php
|
47
|
*/
|
48
|
function adaptivetheme_process_page(&$vars) {
|
49
|
global $theme_key;
|
50
|
$theme_name = $theme_key;
|
51
|
|
52
|
// Attributes
|
53
|
$vars['page_attributes'] = empty($vars['page_attributes_array']) ? '' : drupal_attributes($vars['page_attributes_array']);
|
54
|
$vars['header_attributes'] = empty($vars['header_attributes_array']) ? '' : drupal_attributes($vars['header_attributes_array']);
|
55
|
$vars['branding_attributes'] = empty($vars['branding_attributes_array']) ? '' : drupal_attributes($vars['branding_attributes_array']);
|
56
|
$vars['hgroup_attributes'] = empty($vars['hgroup_attributes_array']) ? '' : drupal_attributes($vars['hgroup_attributes_array']);
|
57
|
$vars['site_name_attributes'] = empty($vars['site_name_attributes_array']) ? '' : drupal_attributes($vars['site_name_attributes_array']);
|
58
|
$vars['site_slogan_attributes'] = empty($vars['site_slogan_attributes_array']) ? '' : drupal_attributes($vars['site_slogan_attributes_array']);
|
59
|
$vars['content_header_attributes'] = empty($vars['content_header_attributes_array']) ? '' : drupal_attributes($vars['content_header_attributes_array']);
|
60
|
$vars['footer_attributes'] = empty($vars['footer_attributes_array']) ? '' : drupal_attributes($vars['footer_attributes_array']);
|
61
|
|
62
|
// Theme the menu bars
|
63
|
if (!empty($vars['primary_navigation'])) {
|
64
|
$vars['primary_navigation'] = theme('menubar', array('menu' => $vars['primary_navigation'],'type' => 'primary'));
|
65
|
}
|
66
|
if (!empty($vars['secondary_navigation'])) {
|
67
|
$vars['secondary_navigation'] = theme('menubar', array('menu' => $vars['secondary_navigation'], 'type' => 'secondary'));
|
68
|
}
|
69
|
|
70
|
// Generate the wrapper element for the main content
|
71
|
$vars['tag'] = $vars['title'] ? 'section' : 'div';
|
72
|
|
73
|
// Process enabled Extensions
|
74
|
if (at_get_setting('enable_extensions', $theme_name) === 1) {
|
75
|
if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
|
76
|
// Add page template suggestions per node type, but make the suggestion weak
|
77
|
// so other suggestions can easily override it.
|
78
|
if (at_get_setting('page_content_type_suggestions', $theme_name) === 1) {
|
79
|
if (isset($vars['node'])) {
|
80
|
$suggestion = 'page__' . $vars['node']->type;
|
81
|
array_unshift($vars['theme_hook_suggestions'], $suggestion);
|
82
|
}
|
83
|
}
|
84
|
// Force full width wrapper template suggestion if enabled
|
85
|
if (at_get_setting('page_full_width_wrappers', $theme_name) === 1) {
|
86
|
array_unshift($vars['theme_hook_suggestions'], 'page__full_width_wrappers');
|
87
|
}
|
88
|
// Remove the frontpage title if set in theme settings
|
89
|
if (at_get_setting('frontpage_remove_title') === 1 && $vars['is_front'] === TRUE) {
|
90
|
$vars['title'] = '';
|
91
|
drupal_set_title('');
|
92
|
if (isset($vars['node'])) {
|
93
|
$vars['node']->title = '';
|
94
|
}
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
|
99
|
// Page template suggestions for Panels pages
|
100
|
if (module_exists('page_manager')) {
|
101
|
if($panel_page = page_manager_get_current_page()) {
|
102
|
// add a generic suggestion for all panel pages
|
103
|
$suggestions[] = 'page__panels';
|
104
|
// add the panel page machine name to the template suggestions
|
105
|
$suggestions[] = 'page__' . $panel_page['name'];
|
106
|
// merge the suggestions in to the existing suggestions (as more specific than the existing suggestions)
|
107
|
$vars['theme_hook_suggestions'] = array_merge($vars['theme_hook_suggestions'], $suggestions);
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Process variables for region.tpl.php
|
114
|
*/
|
115
|
function adaptivetheme_process_region(&$vars) {
|
116
|
// Initialize and populate the outer wrapper variables
|
117
|
$vars['outer_prefix'] = '<div class="' . $vars['classes'] . '">';
|
118
|
$vars['outer_suffix'] = '</div>';
|
119
|
|
120
|
// Initialize and populate the inner wrapper variables
|
121
|
$vars['inner_prefix'] = '<div class="region-inner clearfix">';
|
122
|
$vars['inner_suffix'] = '</div>';
|
123
|
|
124
|
// Some regions need different or no markup
|
125
|
// Use a region template with no wrappers for the main content
|
126
|
if ($vars['region'] === 'content') {
|
127
|
$vars['outer_prefix'] = '';
|
128
|
$vars['outer_suffix'] = '';
|
129
|
$vars['inner_prefix'] = '';
|
130
|
$vars['inner_suffix'] = '';
|
131
|
}
|
132
|
// Menu bar needs an id, nav class and no inner wrapper
|
133
|
if ($vars['region'] === 'menu_bar') {
|
134
|
$vars['outer_prefix'] = '<div id="menu-bar" class="nav clearfix">';
|
135
|
$vars['inner_prefix'] = '';
|
136
|
$vars['inner_suffix'] = '';
|
137
|
}
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Process variables for block.tpl.php
|
142
|
*/
|
143
|
function adaptivetheme_process_block(&$vars) {
|
144
|
// Now we know all the block $tag's, we can generate our wrapper, $tag is
|
145
|
// set in preprocess. We cant introduce these in preprocess due to attributes
|
146
|
// and classes not being flattened untill we hit process.
|
147
|
$vars['outer_prefix'] = '<' . $vars['tag'] . ' id="' . $vars['block_html_id'] . '" class="' . $vars['classes'] . '" ' . $vars['attributes'] . '>';
|
148
|
$vars['outer_suffix'] = '</' . $vars['tag'] . '>';
|
149
|
|
150
|
// Block inner attributes
|
151
|
$vars['block_inner_attributes'] = empty($vars['block_inner_attributes_array']) ? '' : drupal_attributes($vars['block_inner_attributes_array']);
|
152
|
|
153
|
// Populate the default inner wrappers
|
154
|
$vars['inner_prefix'] = '<div' . $vars['block_inner_attributes'] . '>';
|
155
|
$vars['inner_suffix'] = '</div>';
|
156
|
|
157
|
// Wrap the content variable in a div with attributes
|
158
|
$vars['content_processed'] = '<div' . $vars['content_attributes'] . '>' . $vars['content'] . '</div>';
|
159
|
|
160
|
// The menu bar region gets special treatment for the block template
|
161
|
if ($vars['block']->region === 'menu_bar') {
|
162
|
$vars['inner_prefix'] = '';
|
163
|
$vars['inner_suffix'] = '';
|
164
|
$vars['content_processed'] = $vars['content']; // remove the default wrapper
|
165
|
}
|
166
|
// Navigation or menu blocks get special treatment in these regions
|
167
|
if ($vars['block']->region === 'leaderboard' || $vars['block']->region === 'header') {
|
168
|
if ($vars['tag'] == 'nav') {
|
169
|
$vars['content_processed'] = $vars['content']; // remove the default wrapper
|
170
|
}
|
171
|
}
|
172
|
|
173
|
// Some blocks look bad with wrappers so we strip them
|
174
|
if ($vars['block']->region === 'content') {
|
175
|
$vars['inner_prefix'] = '';
|
176
|
$vars['inner_suffix'] = '';
|
177
|
$vars['content_processed'] = $vars['content'];
|
178
|
}
|
179
|
if ($vars['block']->module === 'panels_mini') {
|
180
|
$vars['inner_prefix'] = '';
|
181
|
$vars['inner_suffix'] = '';
|
182
|
}
|
183
|
|
184
|
// Provide additional suggestions so the block__menu suggestion can be overridden easily
|
185
|
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->module;
|
186
|
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->delta;
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* Process variables for node.tpl.php
|
191
|
*/
|
192
|
function adaptivetheme_process_node(&$vars) {
|
193
|
global $theme_key;
|
194
|
$theme_name = $theme_key;
|
195
|
|
196
|
// Strip default drupal classes if not required
|
197
|
if (at_get_setting('extra_article_classes', $theme_name) === 0) {
|
198
|
$classes = explode(' ', $vars['classes']);
|
199
|
$striped_classes = array('node-sticky', 'node-promoted', 'node-teaser', 'node-preview');
|
200
|
foreach ($striped_classes as $class) {
|
201
|
if (in_array($class, $classes)) {
|
202
|
$classes = str_replace($class, '', $classes);
|
203
|
}
|
204
|
}
|
205
|
$vars['classes'] = trim(implode(' ', $classes));
|
206
|
}
|
207
|
|
208
|
// Flatten the additional wrapper attributes array
|
209
|
$vars['header_attributes'] = empty($vars['header_attributes_array']) ? '' : drupal_attributes($vars['header_attributes_array']);
|
210
|
$vars['footer_attributes'] = empty($vars['footer_attributes_array']) ? '' : drupal_attributes($vars['footer_attributes_array']);
|
211
|
$vars['links_attributes'] = empty($vars['links_attributes_array']) ? '' : drupal_attributes($vars['links_attributes_array']);
|
212
|
|
213
|
// If a panels layout is being rendered by Display Suite in a node we wrap the
|
214
|
// the layout in markup to make the themers life a little easier and remove
|
215
|
// the requirement to add a DS template override.
|
216
|
if (isset($vars['rendered_by_ds']) && $vars['rendered_by_ds'] == TRUE) {
|
217
|
$vars['panel_prefix'] = '<article id="node-' . $vars['node']->nid . '" class="' . $vars['classes'] . ' rendered-by-ds clearfix"' . $vars['attributes'] . '>';
|
218
|
$vars['panel_prefix'] .= render($vars['title_prefix']);
|
219
|
$vars['panel_prefix'] .= render($vars['title_suffix']);
|
220
|
$vars['panel_suffix'] = '</article>';
|
221
|
}
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* Process variables for comment.tpl.php
|
226
|
*/
|
227
|
function adaptivetheme_process_comment(&$vars) {
|
228
|
global $theme_key;
|
229
|
$theme_name = $theme_key;
|
230
|
|
231
|
// Strip default drupal classes if not required.
|
232
|
if (at_get_setting('extra_comment_classes', $theme_name) === 0) {
|
233
|
$classes = explode(' ', $vars['classes']);
|
234
|
$striped_classes = array('comment-by-anonymous', 'comment-by-node-autho', 'comment-by-viewer', 'comment-new');
|
235
|
foreach ($striped_classes as $class) {
|
236
|
if (in_array($class, $classes)) {
|
237
|
$classes = str_replace($class, '', $classes);
|
238
|
}
|
239
|
}
|
240
|
$vars['classes'] = trim(implode(' ', $classes));
|
241
|
}
|
242
|
|
243
|
// Flatten the additional wrapper attributes array
|
244
|
$vars['header_attributes'] = empty($vars['header_attributes_array']) ? '' : drupal_attributes($vars['header_attributes_array']);
|
245
|
$vars['footer_attributes'] = empty($vars['footer_attributes_array']) ? '' : drupal_attributes($vars['footer_attributes_array']);
|
246
|
$vars['links_attributes'] = empty($vars['links_attributes_array']) ? '' : drupal_attributes($vars['links_attributes_array']);
|
247
|
}
|
248
|
|
249
|
/**
|
250
|
* Process variables for adaptivtheme_menubar()
|
251
|
*/
|
252
|
function adaptivetheme_process_menubar(&$vars) {
|
253
|
// The default theme implementation is a function, so template_process() does
|
254
|
// not automatically run, so we need to flatten the classes and attributes
|
255
|
// here. For best performance, only call drupal_attributes() when needed, and
|
256
|
// note that template_preprocess_menubar() does not initialize the
|
257
|
// *_attributes_array variables.
|
258
|
$vars['classes'] = implode(' ', $vars['classes_array']);
|
259
|
$vars['attributes'] = empty($vars['attributes_array']) ? '' : drupal_attributes($vars['attributes_array']);
|
260
|
$vars['content_attributes'] = empty($vars['content_attributes_array']) ? '' : drupal_attributes($vars['content_attributes_array']);
|
261
|
}
|
262
|
|
263
|
/**
|
264
|
* Process variables for maintenance-page.tpl.php
|
265
|
*/
|
266
|
function adaptivetheme_process_maintenance_page(&$vars) {
|
267
|
// Render polyfills
|
268
|
if ($vars['polyfills']) {
|
269
|
$vars['polyfills'] = drupal_render($vars['polyfills']);
|
270
|
}
|
271
|
}
|
272
|
|
273
|
/**
|
274
|
* Process variables for user-profile.tpl.php
|
275
|
*/
|
276
|
function adaptivetheme_process_user_profile(&$vars) {
|
277
|
// If a panels layout is rendered by Display Suite in a user profile we wrap the
|
278
|
// the layout in markup to make the themers life a little easier and remove
|
279
|
// the requirement to add a DS template override.
|
280
|
if (isset($vars['rendered_by_ds']) && $vars['rendered_by_ds'] == TRUE) {
|
281
|
$vars['panel_prefix'] = '<article id="user-' . $vars['user']->uid . '" class="' . $vars['classes'] . ' rendered-by-ds clearfix"' . $vars['attributes'] . '>';
|
282
|
$vars['panel_suffix'] = '</article>';
|
283
|
}
|
284
|
}
|