by JohnAlbin: Rename zen-columns-fixed mixin to just zen-columns.
[project/zen.git] / template.php
CommitLineData
0c91c6b4 1<?php
0c91c6b4 2/**
8c1acf80 3 * @file
0b1037f4 4 * Contains theme override functions and preprocess functions for the Zen theme.
7c5fa196 5 *
0b1037f4 6 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
28511ba8
J
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 * http://drupal.org/node/193318
960bac1c
TS
12 */
13
89804871 14// Auto-rebuild the theme registry during theme development.
74cf7b61 15if (theme_get_setting('zen_rebuild_registry') && !defined('MAINTENANCE_MODE')) {
c37ef432 16 // Rebuild .info data.
e28f5335 17 system_rebuild_theme_data();
c37ef432
J
18 // Rebuild theme registry.
19 drupal_theme_rebuild();
89804871 20}
7c5fa196 21
719059ea 22
4f5c1d0c
J
23/**
24 * Implements HOOK_theme().
52521ba9 25 */
4f5c1d0c 26function zen_theme(&$existing, $type, $theme, $path) {
fb2d48c9 27 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.theme-registry.inc';
4f5c1d0c
J
28 return _zen_theme($existing, $type, $theme, $path);
29}
52521ba9 30
7c5fa196
J
31/**
32 * Return a themed breadcrumb trail.
7081db43 33 *
3f537ac5
J
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.
7c5fa196
J
40 * @return
41 * A string containing the breadcrumb output.
7081db43 42 */
fb2d48c9
J
43function zen_breadcrumb($variables) {
44 $breadcrumb = $variables['breadcrumb'];
d60c8c02 45 // Determine if we are to display the breadcrumb.
59794464 46 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
52521ba9 47 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
59794464 48
d60c8c02 49 // Optionally get rid of the homepage link.
59794464 50 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
52521ba9 51 if (!$show_breadcrumb_home) {
52521ba9
J
52 array_shift($breadcrumb);
53 }
59794464 54
d60c8c02 55 // Return the breadcrumb with separators.
52521ba9 56 if (!empty($breadcrumb)) {
59794464 57 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
d60c8c02
J
58 $trailing_separator = $title = '';
59 if (theme_get_setting('zen_breadcrumb_title')) {
660c4307
J
60 $item = menu_get_item();
61 if (!empty($item['tab_parent'])) {
f134138f 62 // If we are on a non-default tab, use the tab's title.
660c4307
J
63 $title = check_plain($item['title']);
64 }
65 else {
66 $title = drupal_get_title();
67 }
68 if ($title) {
b6656287
J
69 $trailing_separator = $breadcrumb_separator;
70 }
d60c8c02
J
71 }
72 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
73 $trailing_separator = $breadcrumb_separator;
74 }
95b795f9
J
75
76 // Provide a navigational heading to give context for breadcrumb links to
3f537ac5
J
77 // screen-reader users.
78 if (empty($variables['title'])) {
79 $variables['title'] = t('You are here');
80 }
81 // Unless overridden by a preprocess function, make the heading invisible.
82 if (!isset($variables['title_attributes_array']['class'])) {
83 $variables['title_attributes_array']['class'][] = 'element-invisible';
84 }
85 $heading = '<h2' . drupal_attributes($variables['title_attributes_array']) . '>' . $variables['title'] . '</h2>';
95b795f9 86
3f537ac5 87 return '<div class="breadcrumb">' . $heading . implode($breadcrumb_separator, $breadcrumb) . $trailing_separator . $title . '</div>';
52521ba9 88 }
7c5fa196 89 }
d60c8c02 90 // Otherwise, return an empty string.
52521ba9 91 return '';
7c5fa196
J
92}
93
4f5c1d0c 94/**
da899813 95 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
4f5c1d0c 96 */
2e8bbb5a
J
97function zen_menu_local_tasks(&$variables) {
98 $output = '';
4f5c1d0c 99
d8693b08
J
100 if ($primary = drupal_render($variables['primary'])) {
101 $output .= '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
102 $output .= '<ul class="tabs primary clearfix">' . $primary . '</ul>';
4f5c1d0c 103 }
d8693b08
J
104 if ($secondary = drupal_render($variables['secondary'])) {
105 $output .= '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
106 $output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>';
4f5c1d0c
J
107 }
108
109 return $output;
110}
960bac1c 111
94f89279 112/**
fa28a506 113 * Override or insert variables into the html template.
87695e28 114 *
b6e4708e 115 * @param $variables
0b1037f4 116 * An array of variables to pass to the theme template.
e6f4a124 117 * @param $hook
fa28a506 118 * The name of the template being rendered ("html" in this case.)
87695e28 119 */
b6e4708e 120function zen_preprocess_html(&$variables, $hook) {
c6e9e869
J
121 // Add paths needed or html5shim.
122 $variables['base_path'] = base_path();
dd468c11 123 $variables['path_to_zen'] = drupal_get_path('theme', 'zen');
c6e9e869 124
78d8d215
J
125 // If the user is silly and enables Zen as the theme, add some styles.
126 if ($GLOBALS['theme'] == 'zen') {
dd468c11 127 include_once './' . $variables['path_to_zen'] . '/zen-internals/template.zen.inc';
b6e4708e 128 _zen_preprocess_html($variables, $hook);
78d8d215 129 }
719059ea 130
e0a8f494
J
131 // Classes for body element. Allows advanced theming based on context
132 // (home page, node of certain type, etc.)
b6e4708e 133 if (!$variables['is_front']) {
363d1497 134 // Add unique class for each page.
9faf4798 135 $path = drupal_get_path_alias($_GET['q']);
363d1497 136 // Add unique class for each website section.
8357c010 137 list($section, ) = explode('/', $path, 2);
a2831350
J
138 $arg = explode('/', $_GET['q']);
139 if ($arg[0] == 'node') {
140 if ($arg[1] == 'add') {
363d1497 141 $section = 'node-add';
28511ba8 142 }
63231c44 143 elseif (isset($arg[2]) && is_numeric($arg[1]) && ($arg[2] == 'edit' || $arg[2] == 'delete')) {
a2831350 144 $section = 'node-' . $arg[2];
28511ba8
J
145 }
146 }
b6e4708e 147 $variables['classes_array'][] = drupal_html_class('section-' . $section);
960bac1c 148 }
2041a7c1 149 if (theme_get_setting('zen_wireframes')) {
b6e4708e 150 $variables['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
2041a7c1 151 }
711885f1 152 // Store the menu item since it has some useful information.
b6e4708e
J
153 $variables['menu_item'] = menu_get_item();
154 switch ($variables['menu_item']['page_callback']) {
711885f1
J
155 case 'views_page':
156 // Is this a Views page?
b6e4708e 157 $variables['classes_array'][] = 'page-views';
711885f1
J
158 break;
159 case 'page_manager_page_execute':
160 case 'page_manager_node_view':
161 case 'page_manager_contact_site':
162 // Is this a Panels page?
b6e4708e 163 $variables['classes_array'][] = 'page-panels';
711885f1
J
164 break;
165 }
aeec717d
J
166 $variables['skip_link_anchor'] = theme_get_setting('zen_skip_link_anchor');
167 $variables['skip_link_text'] = theme_get_setting('zen_skip_link_text');
e0a8f494 168}
7c5fa196 169
e0a8f494 170/**
abb4efe9
J
171 * Override or insert variables in the html_tag theme function.
172 */
173function zen_process_html_tag(&$variables) {
174 $tag = &$variables['element'];
175
176 if ($tag['#tag'] == 'style' || $tag['#tag'] == 'script') {
177 // Remove redundant type attribute and CDATA comments.
178 unset($tag['#attributes']['type'], $tag['#value_prefix'], $tag['#value_suffix']);
179
180 // Remove media="all" but leave others unaffected.
181 if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') {
182 unset($tag['#attributes']['media']);
183 }
184 }
185}
186
187/**
1256823c
J
188 * Implement hook_html_head_alter().
189 */
190function zen_html_head_alter(&$head) {
191 // Simplify the meta tag for character encoding.
192 $head['system_meta_content_type']['#attributes'] = array('charset' => str_replace('text/html; charset=', '', $head['system_meta_content_type']['#attributes']['content']));
193}
194
195/**
551c3139
J
196 * Override or insert variables into the page template.
197 *
198 * @param $variables
199 * An array of variables to pass to the theme template.
200 * @param $hook
201 * The name of the template being rendered ("page" in this case.)
202 */
203function zen_preprocess_page(&$variables, $hook) {
204 // Find the title of the menu used by the secondary links.
205 $secondary_links = variable_get('menu_secondary_links_source', 'user-menu');
9d330c3b
J
206 if ($secondary_links) {
207 $menus = function_exists('menu_get_menus') ? menu_get_menus() : menu_list_system_menus();
208 $variables['secondary_menu_heading'] = $menus[$secondary_links];
209 }
210 else {
211 $variables['secondary_menu_heading'] = '';
212 }
551c3139
J
213}
214
215/**
3183d194
J
216 * Override or insert variables into the maintenance page template.
217 *
b6e4708e 218 * @param $variables
3183d194
J
219 * An array of variables to pass to the theme template.
220 * @param $hook
31c1fbc2 221 * The name of the template being rendered ("maintenance_page" in this case.)
3183d194 222 */
b6e4708e 223function zen_preprocess_maintenance_page(&$variables, $hook) {
f92efd05
J
224 // Add paths needed or html5shim.
225 $variables['base_path'] = base_path();
226 $variables['path_to_zen'] = drupal_get_path('theme', 'zen');
227
3183d194
J
228 // If Zen is the maintenance theme, add some styles.
229 if ($GLOBALS['theme'] == 'zen') {
fb2d48c9 230 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc';
b6e4708e 231 _zen_preprocess_html($variables, $hook);
3183d194 232 }
3183d194
J
233}
234
235/**
0b1037f4 236 * Override or insert variables into the node templates.
e0a8f494 237 *
b6e4708e 238 * @param $variables
0b1037f4 239 * An array of variables to pass to the theme template.
e6f4a124 240 * @param $hook
0b1037f4 241 * The name of the template being rendered ("node" in this case.)
e0a8f494 242 */
b6e4708e 243function zen_preprocess_node(&$variables, $hook) {
e7ce78eb 244 // Add $unpublished variable.
b6e4708e 245 $variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE;
911d5130 246
bfea55ea
J
247 // Add a class for the view mode.
248 if (!$variables['teaser']) {
249 $variables['classes_array'][] = 'view-mode-' . $variables['view_mode'];
250 }
251
e7ce78eb 252 // Add a class to show node is authored by current user.
b6e4708e
J
253 if ($variables['uid'] && $variables['uid'] == $GLOBALS['user']->uid) {
254 $variables['classes_array'][] = 'node-by-viewer';
c91ed8a5 255 }
4e316b5a 256
b6e4708e 257 $variables['title_attributes_array']['class'][] = 'node-title';
e0a8f494 258}
7c5fa196 259
e0a8f494 260/**
0b1037f4 261 * Override or insert variables into the comment templates.
e0a8f494 262 *
b6e4708e 263 * @param $variables
0b1037f4 264 * An array of variables to pass to the theme template.
e6f4a124 265 * @param $hook
0b1037f4 266 * The name of the template being rendered ("comment" in this case.)
e0a8f494 267 */
b6e4708e 268function zen_preprocess_comment(&$variables, $hook) {
e8e12945 269 // If comment subjects are disabled, don't display them.
b6e4708e
J
270 if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) {
271 $variables['title'] = '';
e8e12945
J
272 }
273
d2d67844
J
274 // Anonymous class is broken in core. See #1110650
275 if ($variables['comment']->uid == 0) {
276 $variables['classes_array'][] = 'comment-by-anonymous';
277 }
e8e12945 278 // Zebra striping.
b6e4708e
J
279 if ($variables['id'] == 1) {
280 $variables['classes_array'][] = 'first';
e8e12945 281 }
b6e4708e
J
282 if ($variables['id'] == $variables['node']->comment_count) {
283 $variables['classes_array'][] = 'last';
e8e12945 284 }
b6e4708e 285 $variables['classes_array'][] = $variables['zebra'];
e8e12945 286
b6e4708e 287 $variables['title_attributes_array']['class'][] = 'comment-title';
960bac1c 288}
4dd0f1bf
JR
289
290/**
94f89279
J
291 * Preprocess variables for region.tpl.php
292 *
7f47e51d
J
293 * @param $variables
294 * An array of variables to pass to the theme template.
295 * @param $hook
296 * The name of the template being rendered ("region" in this case.)
94f89279 297 */
b6e4708e 298function zen_preprocess_region(&$variables, $hook) {
6b8155aa 299 // Sidebar regions get some extra classes and a common template suggestion.
b6e4708e
J
300 if (strpos($variables['region'], 'sidebar_') === 0) {
301 $variables['classes_array'][] = 'column';
302 $variables['classes_array'][] = 'sidebar';
303 $variables['theme_hook_suggestions'][] = 'region__sidebar';
6b8155aa 304 // Allow a region-specific template to override Zen's region--sidebar.
b6e4708e 305 $variables['theme_hook_suggestions'][] = 'region__' . $variables['region'];
995d309c 306 }
786931f7
J
307 // Use a bare template for the content region.
308 elseif ($variables['region'] == 'content') {
309 $variables['theme_hook_suggestions'][] = 'region__bare';
310 }
94f89279
J
311}
312
313/**
0b1037f4 314 * Override or insert variables into the block templates.
28511ba8 315 *
b6e4708e 316 * @param $variables
0b1037f4 317 * An array of variables to pass to the theme template.
e6f4a124 318 * @param $hook
0b1037f4 319 * The name of the template being rendered ("block" in this case.)
28511ba8 320 */
b6e4708e 321function zen_preprocess_block(&$variables, $hook) {
786931f7
J
322 // Use a bare template for the page's main content.
323 if ($variables['block_html_id'] == 'block-system-main') {
324 $variables['theme_hook_suggestions'][] = 'block__bare';
325 }
326
288001f7 327 // Classes describing the position of the block within the region.
b6e4708e
J
328 if ($variables['block_id'] == 1) {
329 $variables['classes_array'][] = 'first';
288001f7
J
330 }
331 // The last_in_region property is set in zen_page_alter().
b6e4708e
J
332 if (isset($variables['block']->last_in_region)) {
333 $variables['classes_array'][] = 'last';
288001f7 334 }
b6e4708e 335 $variables['classes_array'][] = $variables['block_zebra'];
4e316b5a 336
b6e4708e 337 $variables['title_attributes_array']['class'][] = 'block-title';
3183d194 338}
a3f7ecae
J
339
340/**
341 * Override or insert variables into the block templates.
342 *
b6e4708e 343 * @param $variables
a3f7ecae
J
344 * An array of variables to pass to the theme template.
345 * @param $hook
346 * The name of the template being rendered ("block" in this case.)
347 */
b6e4708e 348function zen_process_block(&$variables, $hook) {
a3f7ecae 349 // Drupal 7 should use a $title variable instead of $block->subject.
b6e4708e 350 $variables['title'] = $variables['block']->subject;
a3f7ecae 351}
288001f7
J
352
353/**
354 * Implements hook_page_alter().
355 *
356 * Look for the last block in the region. This is impossible to determine from
357 * within a preprocess_block function.
358 *
359 * @param $page
360 * Nested array of renderable elements that make up the page.
361 */
362function zen_page_alter(&$page) {
363 // Look in each visible region for blocks.
364 foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) {
365 if (!empty($page[$region])) {
366 // Find the last block in the region.
367 $blocks = array_reverse(element_children($page[$region]));
368 while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) {
369 array_shift($blocks);
370 }
371 if ($blocks) {
372 $page[$region][$blocks[0]]['#block']->last_in_region = TRUE;
373 }
374 }
375 }
376}
e63ff516
J
377
378/**
379 * Implements hook_form_BASE_FORM_ID_alter().
380 *
381 * Prevent user-facing field styling from screwing up node edit forms by
382 * renaming the classes on the node edit form's field wrappers.
383 */
384function zen_form_node_form_alter(&$form, &$form_state, $form_id) {
385 // Remove if #1245218 is backported to D7 core.
386 foreach (array_keys($form) as $item) {
387 if (strpos($item, 'field_') === 0) {
388 if (!empty($form[$item]['#attributes']['class'])) {
389 foreach ($form[$item]['#attributes']['class'] as &$class) {
390 if (strpos($class, 'field-type-') === 0 || strpos($class, 'field-name-') === 0) {
391 // Make the class different from that used in theme_field().
392 $class = 'form-' . $class;
393 }
394 }
395 }
396 }
397 }
398}