root / drupal7 / sites / all / themes / zen / template.php @ 7dbec6b0
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* @file
|
4 |
* Contains functions to alter Drupal's markup for the Zen theme.
|
5 |
*
|
6 |
* IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
|
7 |
*
|
8 |
* The base Zen theme is designed to be easily extended by its sub-themes. You
|
9 |
* shouldn't modify this or any of the CSS or PHP files in the root zen/ folder.
|
10 |
* See the online documentation for more information:
|
11 |
* https://drupal.org/documentation/theme/zen
|
12 |
*/
|
13 |
|
14 |
// Auto-rebuild the theme registry during theme development.
|
15 |
if (theme_get_setting('zen_rebuild_registry') && !defined('MAINTENANCE_MODE')) { |
16 |
// Rebuild .info data.
|
17 |
system_rebuild_theme_data(); |
18 |
// Rebuild theme registry.
|
19 |
drupal_theme_rebuild(); |
20 |
} |
21 |
|
22 |
|
23 |
/**
|
24 |
* Implements HOOK_theme().
|
25 |
*/
|
26 |
function zen_theme(&$existing, $type, $theme, $path) { |
27 |
include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.theme-registry.inc'; |
28 |
return _zen_theme($existing, $type, $theme, $path); |
29 |
} |
30 |
|
31 |
/**
|
32 |
* Return a themed breadcrumb trail.
|
33 |
*
|
34 |
* @param $variables
|
35 |
* - title: An optional string to be used as a navigational heading to give
|
36 |
* context for breadcrumb links to screen-reader users.
|
37 |
* - title_attributes_array: Array of HTML attributes for the title. It is
|
38 |
* flattened into a string within the theme function.
|
39 |
* - breadcrumb: An array containing the breadcrumb links.
|
40 |
* @return
|
41 |
* A string containing the breadcrumb output.
|
42 |
*/
|
43 |
function zen_breadcrumb($variables) { |
44 |
$breadcrumb = $variables['breadcrumb']; |
45 |
$output = ''; |
46 |
|
47 |
// Determine if we are to display the breadcrumb.
|
48 |
$show_breadcrumb = theme_get_setting('zen_breadcrumb'); |
49 |
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') { |
50 |
|
51 |
// Optionally get rid of the homepage link.
|
52 |
$show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home'); |
53 |
if (!$show_breadcrumb_home) { |
54 |
array_shift($breadcrumb); |
55 |
} |
56 |
|
57 |
// Return the breadcrumb with separators.
|
58 |
if (!empty($breadcrumb)) { |
59 |
$breadcrumb_separator = filter_xss_admin(theme_get_setting('zen_breadcrumb_separator')); |
60 |
$trailing_separator = $title = ''; |
61 |
if (theme_get_setting('zen_breadcrumb_title')) { |
62 |
$item = menu_get_item();
|
63 |
if (!empty($item['tab_parent'])) { |
64 |
// If we are on a non-default tab, use the tab's title.
|
65 |
$breadcrumb[] = check_plain($item['title']); |
66 |
} |
67 |
else {
|
68 |
$breadcrumb[] = drupal_get_title();
|
69 |
} |
70 |
} |
71 |
elseif (theme_get_setting('zen_breadcrumb_trailing')) { |
72 |
$trailing_separator = $breadcrumb_separator; |
73 |
} |
74 |
|
75 |
// Provide a navigational heading to give context for breadcrumb links to
|
76 |
// screen-reader users.
|
77 |
if (empty($variables['title'])) { |
78 |
$variables['title'] = t('You are here'); |
79 |
} |
80 |
// Unless overridden by a preprocess function, make the heading invisible.
|
81 |
if (!isset($variables['title_attributes_array']['class'])) { |
82 |
$variables['title_attributes_array']['class'][] = 'element-invisible'; |
83 |
} |
84 |
|
85 |
// Build the breadcrumb trail.
|
86 |
$output = '<nav class="breadcrumb" role="navigation">'; |
87 |
$output .= '<h2' . drupal_attributes($variables['title_attributes_array']) . '>' . $variables['title'] . '</h2>'; |
88 |
$output .= '<ol><li>' . implode($breadcrumb_separator . '</li><li>', $breadcrumb) . $trailing_separator . '</li></ol>'; |
89 |
$output .= '</nav>'; |
90 |
} |
91 |
} |
92 |
|
93 |
return $output; |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Override or insert variables into the html template.
|
98 |
*
|
99 |
* @param $variables
|
100 |
* An array of variables to pass to the theme template.
|
101 |
* @param $hook
|
102 |
* The name of the template being rendered. This is usually "html", but can
|
103 |
* also be "maintenance_page" since zen_preprocess_maintenance_page() calls
|
104 |
* this function to have consistent variables.
|
105 |
*/
|
106 |
function zen_preprocess_html(&$variables, $hook) { |
107 |
// Add variables and paths needed for HTML5 and responsive support.
|
108 |
$variables['base_path'] = base_path(); |
109 |
$variables['path_to_zen'] = drupal_get_path('theme', 'zen'); |
110 |
// Get settings for HTML5 and responsive support. array_filter() removes
|
111 |
// items from the array that have been disabled.
|
112 |
$html5_respond_meta = array_filter((array) theme_get_setting('zen_html5_respond_meta')); |
113 |
$variables['add_respond_js'] = in_array('respond', $html5_respond_meta); |
114 |
$variables['add_html5_shim'] = in_array('html5', $html5_respond_meta); |
115 |
$variables['default_mobile_metatags'] = in_array('meta', $html5_respond_meta); |
116 |
|
117 |
// If the user is silly and enables Zen as the theme, add some styles.
|
118 |
if ($GLOBALS['theme'] == 'zen') { |
119 |
include_once './' . $variables['path_to_zen'] . '/zen-internals/template.zen.inc'; |
120 |
_zen_preprocess_html($variables, $hook); |
121 |
} |
122 |
|
123 |
// Attributes for html element.
|
124 |
$variables['html_attributes_array'] = array( |
125 |
'lang' => $variables['language']->language, |
126 |
'dir' => $variables['language']->dir, |
127 |
); |
128 |
|
129 |
// Send X-UA-Compatible HTTP header to force IE to use the most recent
|
130 |
// rendering engine.
|
131 |
// This also prevents the IE compatibility mode button to appear when using
|
132 |
// conditional classes on the html tag.
|
133 |
if (is_null(drupal_get_http_header('X-UA-Compatible'))) { |
134 |
drupal_add_http_header('X-UA-Compatible', 'IE=edge'); |
135 |
} |
136 |
|
137 |
$variables['skip_link_anchor'] = check_plain(theme_get_setting('zen_skip_link_anchor')); |
138 |
$variables['skip_link_text'] = check_plain(theme_get_setting('zen_skip_link_text')); |
139 |
|
140 |
// Return early, so the maintenance page does not call any of the code below.
|
141 |
if ($hook != 'html') { |
142 |
return;
|
143 |
} |
144 |
|
145 |
// Serialize RDF Namespaces into an RDFa 1.1 prefix attribute.
|
146 |
if ($variables['rdf_namespaces']) { |
147 |
$prefixes = array(); |
148 |
foreach (explode("\n ", ltrim($variables['rdf_namespaces'])) as $namespace) { |
149 |
// Remove xlmns: and ending quote and fix prefix formatting.
|
150 |
$prefixes[] = str_replace('="', ': ', substr($namespace, 6, -1)); |
151 |
} |
152 |
$variables['rdf_namespaces'] = ' prefix="' . implode(' ', $prefixes) . '"'; |
153 |
} |
154 |
|
155 |
// Classes for body element. Allows advanced theming based on context
|
156 |
// (home page, node of certain type, etc.)
|
157 |
if (!$variables['is_front']) { |
158 |
// Add unique class for each page.
|
159 |
$path = drupal_get_path_alias($_GET['q']); |
160 |
// Add unique class for each website section.
|
161 |
list($section, ) = explode('/', $path, 2); |
162 |
$arg = explode('/', $_GET['q']); |
163 |
if ($arg[0] == 'node' && isset($arg[1])) { |
164 |
if ($arg[1] == 'add') { |
165 |
$section = 'node-add'; |
166 |
} |
167 |
elseif (isset($arg[2]) && is_numeric($arg[1]) && ($arg[2] == 'edit' || $arg[2] == 'delete')) { |
168 |
$section = 'node-' . $arg[2]; |
169 |
} |
170 |
} |
171 |
$variables['classes_array'][] = drupal_html_class('section-' . $section); |
172 |
} |
173 |
if (theme_get_setting('zen_wireframes')) { |
174 |
$variables['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style. |
175 |
} |
176 |
// Store the menu item since it has some useful information.
|
177 |
$variables['menu_item'] = menu_get_item(); |
178 |
if ($variables['menu_item']) { |
179 |
switch ($variables['menu_item']['page_callback']) { |
180 |
case 'views_page': |
181 |
// Is this a Views page?
|
182 |
$variables['classes_array'][] = 'page-views'; |
183 |
break;
|
184 |
case 'page_manager_blog': |
185 |
case 'page_manager_blog_user': |
186 |
case 'page_manager_contact_site': |
187 |
case 'page_manager_contact_user': |
188 |
case 'page_manager_node_add': |
189 |
case 'page_manager_node_edit': |
190 |
case 'page_manager_node_view_page': |
191 |
case 'page_manager_page_execute': |
192 |
case 'page_manager_poll': |
193 |
case 'page_manager_search_page': |
194 |
case 'page_manager_term_view_page': |
195 |
case 'page_manager_user_edit_page': |
196 |
case 'page_manager_user_view_page': |
197 |
// Is this a Panels page?
|
198 |
$variables['classes_array'][] = 'page-panels'; |
199 |
break;
|
200 |
} |
201 |
} |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Override or insert variables into the html templates.
|
206 |
*
|
207 |
* @param $variables
|
208 |
* An array of variables to pass to the theme template.
|
209 |
* @param $hook
|
210 |
* The name of the template being rendered ("html" in this case.)
|
211 |
*/
|
212 |
function zen_process_html(&$variables, $hook) { |
213 |
// Flatten out html_attributes.
|
214 |
$variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* Override or insert variables in the html_tag theme function.
|
219 |
*/
|
220 |
function zen_process_html_tag(&$variables) { |
221 |
$tag = &$variables['element']; |
222 |
|
223 |
if ($tag['#tag'] == 'style' || $tag['#tag'] == 'script') { |
224 |
// Remove redundant CDATA comments.
|
225 |
unset($tag['#value_prefix'], $tag['#value_suffix']); |
226 |
|
227 |
// Remove redundant type attribute.
|
228 |
if (isset($tag['#attributes']['type']) && $tag['#attributes']['type'] !== 'text/ng-template') { |
229 |
unset($tag['#attributes']['type']); |
230 |
} |
231 |
|
232 |
// Remove media="all" but leave others unaffected.
|
233 |
if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') { |
234 |
unset($tag['#attributes']['media']); |
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
/**
|
240 |
* Implement hook_html_head_alter().
|
241 |
*/
|
242 |
function zen_html_head_alter(&$head) { |
243 |
// Simplify the meta tag for character encoding.
|
244 |
if (isset($head['system_meta_content_type']['#attributes']['content'])) { |
245 |
$head['system_meta_content_type']['#attributes'] = array('charset' => str_replace('text/html; charset=', '', $head['system_meta_content_type']['#attributes']['content'])); |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Override or insert variables into the page template.
|
251 |
*
|
252 |
* @param $variables
|
253 |
* An array of variables to pass to the theme template.
|
254 |
* @param $hook
|
255 |
* The name of the template being rendered ("page" in this case.)
|
256 |
*/
|
257 |
function zen_preprocess_page(&$variables, $hook) { |
258 |
// Find the title of the menu used by the secondary links.
|
259 |
$secondary_links = variable_get('menu_secondary_links_source', 'user-menu'); |
260 |
if ($secondary_links) { |
261 |
$menus = function_exists('menu_get_menus') ? menu_get_menus() : menu_list_system_menus(); |
262 |
$variables['secondary_menu_heading'] = isset($menus[$secondary_links]) ? $menus[$secondary_links] : ''; |
263 |
} |
264 |
else {
|
265 |
$variables['secondary_menu_heading'] = ''; |
266 |
} |
267 |
} |
268 |
|
269 |
/**
|
270 |
* Override or insert variables into the maintenance page template.
|
271 |
*
|
272 |
* @param $variables
|
273 |
* An array of variables to pass to the theme template.
|
274 |
* @param $hook
|
275 |
* The name of the template being rendered ("maintenance_page" in this case.)
|
276 |
*/
|
277 |
function zen_preprocess_maintenance_page(&$variables, $hook) { |
278 |
zen_preprocess_html($variables, $hook); |
279 |
// There's nothing maintenance-related in zen_preprocess_page(). Yet.
|
280 |
//zen_preprocess_page($variables, $hook);
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* Override or insert variables into the maintenance page template.
|
285 |
*
|
286 |
* @param $variables
|
287 |
* An array of variables to pass to the theme template.
|
288 |
* @param $hook
|
289 |
* The name of the template being rendered ("maintenance_page" in this case.)
|
290 |
*/
|
291 |
function zen_process_maintenance_page(&$variables, $hook) { |
292 |
zen_process_html($variables, $hook); |
293 |
// Ensure default regions get a variable. Theme authors often forget to remove
|
294 |
// a deleted region's variable in maintenance-page.tpl.
|
295 |
foreach (array('header', 'navigation', 'highlighted', 'help', 'content', 'sidebar_first', 'sidebar_second', 'footer', 'bottom') as $region) { |
296 |
if (!isset($variables[$region])) { |
297 |
$variables[$region] = ''; |
298 |
} |
299 |
} |
300 |
} |
301 |
|
302 |
/**
|
303 |
* Override or insert variables into the node templates.
|
304 |
*
|
305 |
* @param $variables
|
306 |
* An array of variables to pass to the theme template.
|
307 |
* @param $hook
|
308 |
* The name of the template being rendered ("node" in this case.)
|
309 |
*/
|
310 |
function zen_preprocess_node(&$variables, $hook) { |
311 |
// Add $unpublished variable.
|
312 |
$variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE; |
313 |
|
314 |
// Set preview variable to FALSE if it doesn't exist.
|
315 |
$variables['preview'] = isset($variables['preview']) ? $variables['preview'] : FALSE; |
316 |
|
317 |
// Add pubdate to submitted variable.
|
318 |
$variables['pubdate'] = '<time pubdate datetime="' . format_date($variables['node']->created, 'custom', 'c') . '">' . $variables['date'] . '</time>'; |
319 |
if ($variables['display_submitted']) { |
320 |
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['pubdate'])); |
321 |
} |
322 |
|
323 |
// Add a class for the view mode.
|
324 |
if (!$variables['teaser']) { |
325 |
$variables['classes_array'][] = 'view-mode-' . $variables['view_mode']; |
326 |
} |
327 |
|
328 |
// Add a class to show node is authored by current user.
|
329 |
if ($variables['uid'] && $variables['uid'] == $GLOBALS['user']->uid) { |
330 |
$variables['classes_array'][] = 'node-by-viewer'; |
331 |
} |
332 |
|
333 |
$variables['title_attributes_array']['class'][] = 'node__title'; |
334 |
$variables['title_attributes_array']['class'][] = 'node-title'; |
335 |
} |
336 |
|
337 |
/**
|
338 |
* Override or insert variables into the comment templates.
|
339 |
*
|
340 |
* @param $variables
|
341 |
* An array of variables to pass to the theme template.
|
342 |
* @param $hook
|
343 |
* The name of the template being rendered ("comment" in this case.)
|
344 |
*/
|
345 |
function zen_preprocess_comment(&$variables, $hook) { |
346 |
// If comment subjects are disabled, don't display them.
|
347 |
if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) { |
348 |
$variables['title'] = ''; |
349 |
} |
350 |
|
351 |
// Add pubdate to submitted variable.
|
352 |
$variables['pubdate'] = '<time pubdate datetime="' . format_date($variables['comment']->created, 'custom', 'c') . '">' . $variables['created'] . '</time>'; |
353 |
$variables['submitted'] = t('!username replied on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['pubdate'])); |
354 |
|
355 |
// Zebra striping.
|
356 |
if ($variables['id'] == 1) { |
357 |
$variables['classes_array'][] = 'first'; |
358 |
} |
359 |
if ($variables['id'] == $variables['node']->comment_count) { |
360 |
$variables['classes_array'][] = 'last'; |
361 |
} |
362 |
$variables['classes_array'][] = $variables['zebra']; |
363 |
|
364 |
$variables['title_attributes_array']['class'][] = 'comment__title'; |
365 |
$variables['title_attributes_array']['class'][] = 'comment-title'; |
366 |
} |
367 |
|
368 |
/**
|
369 |
* Preprocess variables for region.tpl.php
|
370 |
*
|
371 |
* @param $variables
|
372 |
* An array of variables to pass to the theme template.
|
373 |
* @param $hook
|
374 |
* The name of the template being rendered ("region" in this case.)
|
375 |
*/
|
376 |
function zen_preprocess_region(&$variables, $hook) { |
377 |
// Sidebar regions get some extra classes and a common template suggestion.
|
378 |
if (strpos($variables['region'], 'sidebar_') === 0) { |
379 |
$variables['classes_array'][] = 'column'; |
380 |
$variables['classes_array'][] = 'sidebar'; |
381 |
// Allow a region-specific template to override Zen's region--sidebar.
|
382 |
array_unshift($variables['theme_hook_suggestions'], 'region__sidebar'); |
383 |
} |
384 |
// Use a template with no wrapper for the content region.
|
385 |
elseif ($variables['region'] == 'content') { |
386 |
// Allow a region-specific template to override Zen's region--no-wrapper.
|
387 |
array_unshift($variables['theme_hook_suggestions'], 'region__no_wrapper'); |
388 |
} |
389 |
// Add a SMACSS-style class for header region.
|
390 |
elseif ($variables['region'] == 'header') { |
391 |
array_unshift($variables['classes_array'], 'header__region'); |
392 |
} |
393 |
} |
394 |
|
395 |
/**
|
396 |
* Override or insert variables into the block templates.
|
397 |
*
|
398 |
* @param $variables
|
399 |
* An array of variables to pass to the theme template.
|
400 |
* @param $hook
|
401 |
* The name of the template being rendered ("block" in this case.)
|
402 |
*/
|
403 |
function zen_preprocess_block(&$variables, $hook) { |
404 |
// Use a template with no wrapper for the page's main content.
|
405 |
if ($variables['block_html_id'] == 'block-system-main') { |
406 |
$variables['theme_hook_suggestions'][] = 'block__no_wrapper'; |
407 |
} |
408 |
|
409 |
// Classes describing the position of the block within the region.
|
410 |
if ($variables['block_id'] == 1) { |
411 |
$variables['classes_array'][] = 'first'; |
412 |
} |
413 |
// The last_in_region property is set in zen_page_alter().
|
414 |
if (isset($variables['block']->last_in_region)) { |
415 |
$variables['classes_array'][] = 'last'; |
416 |
} |
417 |
$variables['classes_array'][] = $variables['block_zebra']; |
418 |
|
419 |
$variables['title_attributes_array']['class'][] = 'block__title'; |
420 |
$variables['title_attributes_array']['class'][] = 'block-title'; |
421 |
|
422 |
// Add Aria Roles via attributes.
|
423 |
switch ($variables['block']->module) { |
424 |
case 'system': |
425 |
switch ($variables['block']->delta) { |
426 |
case 'main': |
427 |
// Note: the "main" role goes in the page.tpl, not here.
|
428 |
break;
|
429 |
case 'help': |
430 |
case 'powered-by': |
431 |
$variables['attributes_array']['role'] = 'complementary'; |
432 |
break;
|
433 |
default:
|
434 |
// Any other "system" block is a menu block.
|
435 |
$variables['attributes_array']['role'] = 'navigation'; |
436 |
break;
|
437 |
} |
438 |
break;
|
439 |
case 'menu': |
440 |
case 'menu_block': |
441 |
case 'blog': |
442 |
case 'book': |
443 |
case 'comment': |
444 |
case 'forum': |
445 |
case 'shortcut': |
446 |
case 'statistics': |
447 |
$variables['attributes_array']['role'] = 'navigation'; |
448 |
break;
|
449 |
case 'search': |
450 |
$variables['attributes_array']['role'] = 'search'; |
451 |
break;
|
452 |
case 'help': |
453 |
case 'aggregator': |
454 |
case 'locale': |
455 |
case 'poll': |
456 |
case 'profile': |
457 |
$variables['attributes_array']['role'] = 'complementary'; |
458 |
break;
|
459 |
case 'node': |
460 |
switch ($variables['block']->delta) { |
461 |
case 'syndicate': |
462 |
$variables['attributes_array']['role'] = 'complementary'; |
463 |
break;
|
464 |
case 'recent': |
465 |
$variables['attributes_array']['role'] = 'navigation'; |
466 |
break;
|
467 |
} |
468 |
break;
|
469 |
case 'user': |
470 |
switch ($variables['block']->delta) { |
471 |
case 'login': |
472 |
$variables['attributes_array']['role'] = 'form'; |
473 |
break;
|
474 |
case 'new': |
475 |
case 'online': |
476 |
$variables['attributes_array']['role'] = 'complementary'; |
477 |
break;
|
478 |
} |
479 |
break;
|
480 |
} |
481 |
} |
482 |
|
483 |
/**
|
484 |
* Override or insert variables into the block templates.
|
485 |
*
|
486 |
* @param $variables
|
487 |
* An array of variables to pass to the theme template.
|
488 |
* @param $hook
|
489 |
* The name of the template being rendered ("block" in this case.)
|
490 |
*/
|
491 |
function zen_process_block(&$variables, $hook) { |
492 |
// Drupal 7 should use a $title variable instead of $block->subject.
|
493 |
$variables['title'] = isset($variables['block']->subject) ? $variables['block']->subject : ''; |
494 |
} |
495 |
|
496 |
/**
|
497 |
* Implements hook_page_alter().
|
498 |
*
|
499 |
* Look for the last block in the region. This is impossible to determine from
|
500 |
* within a preprocess_block function.
|
501 |
*
|
502 |
* @param $page
|
503 |
* Nested array of renderable elements that make up the page.
|
504 |
*/
|
505 |
function zen_page_alter(&$page) { |
506 |
// Look in each visible region for blocks.
|
507 |
foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) { |
508 |
if (!empty($page[$region])) { |
509 |
// Find the last block in the region.
|
510 |
$blocks = array_reverse(element_children($page[$region])); |
511 |
while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) { |
512 |
array_shift($blocks); |
513 |
} |
514 |
if ($blocks) { |
515 |
$page[$region][$blocks[0]]['#block']->last_in_region = TRUE; |
516 |
} |
517 |
} |
518 |
} |
519 |
} |
520 |
|
521 |
/**
|
522 |
* Implements hook_form_BASE_FORM_ID_alter().
|
523 |
*
|
524 |
* Prevent user-facing field styling from screwing up node edit forms by
|
525 |
* renaming the classes on the node edit form's field wrappers.
|
526 |
*/
|
527 |
function zen_form_node_form_alter(&$form, &$form_state, $form_id) { |
528 |
// Remove if #1245218 is backported to D7 core.
|
529 |
foreach (array_keys($form) as $item) { |
530 |
if (strpos($item, 'field_') === 0) { |
531 |
if (!empty($form[$item]['#attributes']['class'])) { |
532 |
foreach ($form[$item]['#attributes']['class'] as &$class) { |
533 |
// Core bug: the field-type-text-with-summary class is used as a JS hook.
|
534 |
if ($class != 'field-type-text-with-summary' && strpos($class, 'field-type-') === 0 || strpos($class, 'field-name-') === 0) { |
535 |
// Make the class different from that used in theme_field().
|
536 |
$class = 'form-' . $class; |
537 |
} |
538 |
} |
539 |
} |
540 |
} |
541 |
} |
542 |
} |
543 |
|
544 |
/**
|
545 |
* Returns HTML for primary and secondary local tasks.
|
546 |
*
|
547 |
* @ingroup themeable
|
548 |
*/
|
549 |
function zen_menu_local_tasks(&$variables) { |
550 |
$output = ''; |
551 |
|
552 |
// Add theme hook suggestions for tab type.
|
553 |
foreach (array('primary', 'secondary') as $type) { |
554 |
if (!empty($variables[$type])) { |
555 |
foreach (array_keys($variables[$type]) as $key) { |
556 |
if (isset($variables[$type][$key]['#theme']) && ($variables[$type][$key]['#theme'] == 'menu_local_task' || is_array($variables[$type][$key]['#theme']) && in_array('menu_local_task', $variables[$type][$key]['#theme']))) { |
557 |
$variables[$type][$key]['#theme'] = array('menu_local_task__' . $type, 'menu_local_task'); |
558 |
} |
559 |
} |
560 |
} |
561 |
} |
562 |
|
563 |
if (!empty($variables['primary'])) { |
564 |
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>'; |
565 |
$variables['primary']['#prefix'] .= '<ul class="tabs-primary tabs primary">'; |
566 |
$variables['primary']['#suffix'] = '</ul>'; |
567 |
$output .= drupal_render($variables['primary']); |
568 |
} |
569 |
if (!empty($variables['secondary'])) { |
570 |
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>'; |
571 |
$variables['secondary']['#prefix'] .= '<ul class="tabs-secondary tabs secondary">'; |
572 |
$variables['secondary']['#suffix'] = '</ul>'; |
573 |
$output .= drupal_render($variables['secondary']); |
574 |
} |
575 |
|
576 |
return $output; |
577 |
} |
578 |
|
579 |
/**
|
580 |
* Returns HTML for a single local task link.
|
581 |
*
|
582 |
* @ingroup themeable
|
583 |
*/
|
584 |
function zen_menu_local_task($variables) { |
585 |
$type = $class = FALSE; |
586 |
|
587 |
$link = $variables['element']['#link']; |
588 |
$link_text = $link['title']; |
589 |
|
590 |
// Check for tab type set in zen_menu_local_tasks().
|
591 |
if (is_array($variables['element']['#theme'])) { |
592 |
$type = in_array('menu_local_task__secondary', $variables['element']['#theme']) ? 'tabs-secondary' : 'tabs-primary'; |
593 |
} |
594 |
|
595 |
// Add SMACSS-style class names.
|
596 |
if ($type) { |
597 |
$link['localized_options']['attributes']['class'][] = $type . '__tab-link'; |
598 |
$class = $type . '__tab'; |
599 |
} |
600 |
|
601 |
if (!empty($variables['element']['#active'])) { |
602 |
// Add text to indicate active tab for non-visual users.
|
603 |
$active = ' <span class="element-invisible">' . t('(active tab)') . '</span>'; |
604 |
|
605 |
// If the link does not contain HTML already, check_plain() it now.
|
606 |
// After we set 'html'=TRUE the link will not be sanitized by l().
|
607 |
if (empty($link['localized_options']['html'])) { |
608 |
$link['title'] = check_plain($link['title']); |
609 |
} |
610 |
$link['localized_options']['html'] = TRUE; |
611 |
$link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active)); |
612 |
|
613 |
if (!$type) { |
614 |
$class = 'active'; |
615 |
} |
616 |
else {
|
617 |
$link['localized_options']['attributes']['class'][] = 'is-active'; |
618 |
$class .= ' is-active'; |
619 |
} |
620 |
} |
621 |
|
622 |
return '<li' . ($class ? ' class="' . $class . '"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n"; |
623 |
} |
624 |
|
625 |
/**
|
626 |
* Implements hook_preprocess_menu_link().
|
627 |
*/
|
628 |
function zen_preprocess_menu_link(&$variables, $hook) { |
629 |
// Normalize menu item classes to be an array.
|
630 |
if (empty($variables['element']['#attributes']['class'])) { |
631 |
$variables['element']['#attributes']['class'] = array(); |
632 |
} |
633 |
$menu_item_classes =& $variables['element']['#attributes']['class']; |
634 |
if (!is_array($menu_item_classes)) { |
635 |
$menu_item_classes = array($menu_item_classes); |
636 |
} |
637 |
|
638 |
// Normalize menu link classes to be an array.
|
639 |
if (empty($variables['element']['#localized_options']['attributes']['class'])) { |
640 |
$variables['element']['#localized_options']['attributes']['class'] = array(); |
641 |
} |
642 |
$menu_link_classes =& $variables['element']['#localized_options']['attributes']['class']; |
643 |
if (!is_array($menu_link_classes)) { |
644 |
$menu_link_classes = array($menu_link_classes); |
645 |
} |
646 |
|
647 |
// Add BEM-style classes to the menu item classes.
|
648 |
$extra_classes = array('menu__item'); |
649 |
foreach ($menu_item_classes as $key => $class) { |
650 |
switch ($class) { |
651 |
// Menu module classes.
|
652 |
case 'expanded': |
653 |
case 'collapsed': |
654 |
case 'leaf': |
655 |
case 'active': |
656 |
// Menu block module classes.
|
657 |
case 'active-trail': |
658 |
$extra_classes[] = 'is-' . $class; |
659 |
break;
|
660 |
case 'has-children': |
661 |
$extra_classes[] = 'is-parent'; |
662 |
break;
|
663 |
} |
664 |
} |
665 |
$menu_item_classes = array_merge($extra_classes, $menu_item_classes); |
666 |
|
667 |
// Add BEM-style classes to the menu link classes.
|
668 |
$extra_classes = array('menu__link'); |
669 |
if (empty($menu_link_classes)) { |
670 |
$menu_link_classes = array(); |
671 |
} |
672 |
else {
|
673 |
foreach ($menu_link_classes as $key => $class) { |
674 |
switch ($class) { |
675 |
case 'active': |
676 |
case 'active-trail': |
677 |
$extra_classes[] = 'is-' . $class; |
678 |
break;
|
679 |
} |
680 |
} |
681 |
} |
682 |
$menu_link_classes = array_merge($extra_classes, $menu_link_classes); |
683 |
} |
684 |
|
685 |
/**
|
686 |
* Returns HTML for status and/or error messages, grouped by type.
|
687 |
*/
|
688 |
function zen_status_messages($variables) { |
689 |
$display = $variables['display']; |
690 |
$output = ''; |
691 |
|
692 |
$status_heading = array( |
693 |
'status' => t('Status message'), |
694 |
'error' => t('Error message'), |
695 |
'warning' => t('Warning message'), |
696 |
); |
697 |
foreach (drupal_get_messages($display) as $type => $messages) { |
698 |
$output .= "<div class=\"messages--$type messages $type\">\n"; |
699 |
if (!empty($status_heading[$type])) { |
700 |
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n"; |
701 |
} |
702 |
if (count($messages) > 1) { |
703 |
$output .= " <ul class=\"messages__list\">\n"; |
704 |
foreach ($messages as $message) { |
705 |
$output .= ' <li class="messages__item">' . $message . "</li>\n"; |
706 |
} |
707 |
$output .= " </ul>\n"; |
708 |
} |
709 |
else {
|
710 |
$output .= reset($messages); |
711 |
} |
712 |
$output .= "</div>\n"; |
713 |
} |
714 |
return $output; |
715 |
} |
716 |
|
717 |
/**
|
718 |
* Returns HTML for a marker for new or updated content.
|
719 |
*/
|
720 |
function zen_mark($variables) { |
721 |
$type = $variables['type']; |
722 |
|
723 |
if ($type == MARK_NEW) { |
724 |
return ' <mark class="new">' . t('new') . '</mark>'; |
725 |
} |
726 |
elseif ($type == MARK_UPDATED) { |
727 |
return ' <mark class="updated">' . t('updated') . '</mark>'; |
728 |
} |
729 |
} |
730 |
|
731 |
/**
|
732 |
* Alters the default Panels render callback so it removes the panel separator.
|
733 |
*/
|
734 |
function zen_panels_default_style_render_region($variables) { |
735 |
return implode('', $variables['panes']); |
736 |
} |