Issue #1295716 by KrisBulman: system.menu.css only overridden in starterkit, not zen
[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/**
fa28a506 95 * Override or insert variables into the html template.
87695e28 96 *
b6e4708e 97 * @param $variables
0b1037f4 98 * An array of variables to pass to the theme template.
e6f4a124 99 * @param $hook
fa28a506 100 * The name of the template being rendered ("html" in this case.)
87695e28 101 */
b6e4708e 102function zen_preprocess_html(&$variables, $hook) {
190b3d2a 103 // Add paths needed for html5shim.
c6e9e869 104 $variables['base_path'] = base_path();
dd468c11 105 $variables['path_to_zen'] = drupal_get_path('theme', 'zen');
190b3d2a 106 $variables['add_html5_respond_js'] = theme_get_setting('zen_add_html5_respond_js');
c6e9e869 107
78d8d215
J
108 // If the user is silly and enables Zen as the theme, add some styles.
109 if ($GLOBALS['theme'] == 'zen') {
dd468c11 110 include_once './' . $variables['path_to_zen'] . '/zen-internals/template.zen.inc';
b6e4708e 111 _zen_preprocess_html($variables, $hook);
78d8d215 112 }
719059ea 113
104f8e30
J
114 // Attributes for html element.
115 $variables['html_attributes_array'] = array(
116 'lang' => $variables['language']->language,
117 'dir' => $variables['language']->dir,
118 );
119
e0a8f494
J
120 // Classes for body element. Allows advanced theming based on context
121 // (home page, node of certain type, etc.)
b6e4708e 122 if (!$variables['is_front']) {
363d1497 123 // Add unique class for each page.
9faf4798 124 $path = drupal_get_path_alias($_GET['q']);
363d1497 125 // Add unique class for each website section.
8357c010 126 list($section, ) = explode('/', $path, 2);
a2831350
J
127 $arg = explode('/', $_GET['q']);
128 if ($arg[0] == 'node') {
129 if ($arg[1] == 'add') {
363d1497 130 $section = 'node-add';
28511ba8 131 }
63231c44 132 elseif (isset($arg[2]) && is_numeric($arg[1]) && ($arg[2] == 'edit' || $arg[2] == 'delete')) {
a2831350 133 $section = 'node-' . $arg[2];
28511ba8
J
134 }
135 }
b6e4708e 136 $variables['classes_array'][] = drupal_html_class('section-' . $section);
960bac1c 137 }
2041a7c1 138 if (theme_get_setting('zen_wireframes')) {
b6e4708e 139 $variables['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
2041a7c1 140 }
711885f1 141 // Store the menu item since it has some useful information.
b6e4708e
J
142 $variables['menu_item'] = menu_get_item();
143 switch ($variables['menu_item']['page_callback']) {
711885f1
J
144 case 'views_page':
145 // Is this a Views page?
b6e4708e 146 $variables['classes_array'][] = 'page-views';
711885f1
J
147 break;
148 case 'page_manager_page_execute':
149 case 'page_manager_node_view':
150 case 'page_manager_contact_site':
151 // Is this a Panels page?
b6e4708e 152 $variables['classes_array'][] = 'page-panels';
711885f1
J
153 break;
154 }
aeec717d
J
155 $variables['skip_link_anchor'] = theme_get_setting('zen_skip_link_anchor');
156 $variables['skip_link_text'] = theme_get_setting('zen_skip_link_text');
e0a8f494 157}
7c5fa196 158
e0a8f494 159/**
104f8e30
J
160 * Override or insert variables into the html templates.
161 *
162 * @param $variables
163 * An array of variables to pass to the theme template.
164 * @param $hook
165 * The name of the template being rendered ("html" in this case.)
166 */
167function zen_process_html(&$variables, $hook) {
168 // Flatten out html_attributes.
169 $variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']);
170}
171
172/**
abb4efe9
J
173 * Override or insert variables in the html_tag theme function.
174 */
175function zen_process_html_tag(&$variables) {
176 $tag = &$variables['element'];
177
178 if ($tag['#tag'] == 'style' || $tag['#tag'] == 'script') {
179 // Remove redundant type attribute and CDATA comments.
180 unset($tag['#attributes']['type'], $tag['#value_prefix'], $tag['#value_suffix']);
181
182 // Remove media="all" but leave others unaffected.
183 if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') {
184 unset($tag['#attributes']['media']);
185 }
186 }
187}
188
189/**
1256823c
J
190 * Implement hook_html_head_alter().
191 */
192function zen_html_head_alter(&$head) {
193 // Simplify the meta tag for character encoding.
194 $head['system_meta_content_type']['#attributes'] = array('charset' => str_replace('text/html; charset=', '', $head['system_meta_content_type']['#attributes']['content']));
195}
196
197/**
551c3139
J
198 * Override or insert variables into the page template.
199 *
200 * @param $variables
201 * An array of variables to pass to the theme template.
202 * @param $hook
203 * The name of the template being rendered ("page" in this case.)
204 */
205function zen_preprocess_page(&$variables, $hook) {
206 // Find the title of the menu used by the secondary links.
207 $secondary_links = variable_get('menu_secondary_links_source', 'user-menu');
9d330c3b
J
208 if ($secondary_links) {
209 $menus = function_exists('menu_get_menus') ? menu_get_menus() : menu_list_system_menus();
210 $variables['secondary_menu_heading'] = $menus[$secondary_links];
211 }
212 else {
213 $variables['secondary_menu_heading'] = '';
214 }
551c3139
J
215}
216
217/**
3183d194
J
218 * Override or insert variables into the maintenance page template.
219 *
b6e4708e 220 * @param $variables
3183d194
J
221 * An array of variables to pass to the theme template.
222 * @param $hook
31c1fbc2 223 * The name of the template being rendered ("maintenance_page" in this case.)
3183d194 224 */
b6e4708e 225function zen_preprocess_maintenance_page(&$variables, $hook) {
f92efd05
J
226 // Add paths needed or html5shim.
227 $variables['base_path'] = base_path();
228 $variables['path_to_zen'] = drupal_get_path('theme', 'zen');
229
3183d194
J
230 // If Zen is the maintenance theme, add some styles.
231 if ($GLOBALS['theme'] == 'zen') {
fb2d48c9 232 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc';
b6e4708e 233 _zen_preprocess_html($variables, $hook);
3183d194 234 }
104f8e30
J
235
236 // Attributes for html element.
237 $variables['html_attributes_array'] = array(
238 'lang' => $variables['language']->language,
239 'dir' => $variables['language']->dir,
240 );
241}
242
243/**
244 * Override or insert variables into the maintenance page template.
245 *
246 * @param $variables
247 * An array of variables to pass to the theme template.
248 * @param $hook
249 * The name of the template being rendered ("maintenance_page" in this case.)
250 */
251function zen_process_maintenance_page(&$variables, $hook) {
252 // Flatten out html_attributes.
253 $variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']);
3183d194
J
254}
255
256/**
0b1037f4 257 * Override or insert variables into the node templates.
e0a8f494 258 *
b6e4708e 259 * @param $variables
0b1037f4 260 * An array of variables to pass to the theme template.
e6f4a124 261 * @param $hook
0b1037f4 262 * The name of the template being rendered ("node" in this case.)
e0a8f494 263 */
b6e4708e 264function zen_preprocess_node(&$variables, $hook) {
e7ce78eb 265 // Add $unpublished variable.
b6e4708e 266 $variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE;
911d5130 267
bfea55ea
J
268 // Add a class for the view mode.
269 if (!$variables['teaser']) {
270 $variables['classes_array'][] = 'view-mode-' . $variables['view_mode'];
271 }
272
e7ce78eb 273 // Add a class to show node is authored by current user.
b6e4708e
J
274 if ($variables['uid'] && $variables['uid'] == $GLOBALS['user']->uid) {
275 $variables['classes_array'][] = 'node-by-viewer';
c91ed8a5 276 }
4e316b5a 277
b6e4708e 278 $variables['title_attributes_array']['class'][] = 'node-title';
e0a8f494 279}
7c5fa196 280
e0a8f494 281/**
0b1037f4 282 * Override or insert variables into the comment templates.
e0a8f494 283 *
b6e4708e 284 * @param $variables
0b1037f4 285 * An array of variables to pass to the theme template.
e6f4a124 286 * @param $hook
0b1037f4 287 * The name of the template being rendered ("comment" in this case.)
e0a8f494 288 */
b6e4708e 289function zen_preprocess_comment(&$variables, $hook) {
e8e12945 290 // If comment subjects are disabled, don't display them.
b6e4708e
J
291 if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) {
292 $variables['title'] = '';
e8e12945
J
293 }
294
d2d67844
J
295 // Anonymous class is broken in core. See #1110650
296 if ($variables['comment']->uid == 0) {
297 $variables['classes_array'][] = 'comment-by-anonymous';
298 }
e8e12945 299 // Zebra striping.
b6e4708e
J
300 if ($variables['id'] == 1) {
301 $variables['classes_array'][] = 'first';
e8e12945 302 }
b6e4708e
J
303 if ($variables['id'] == $variables['node']->comment_count) {
304 $variables['classes_array'][] = 'last';
e8e12945 305 }
b6e4708e 306 $variables['classes_array'][] = $variables['zebra'];
e8e12945 307
b6e4708e 308 $variables['title_attributes_array']['class'][] = 'comment-title';
960bac1c 309}
4dd0f1bf
JR
310
311/**
94f89279
J
312 * Preprocess variables for region.tpl.php
313 *
7f47e51d
J
314 * @param $variables
315 * An array of variables to pass to the theme template.
316 * @param $hook
317 * The name of the template being rendered ("region" in this case.)
94f89279 318 */
b6e4708e 319function zen_preprocess_region(&$variables, $hook) {
6b8155aa 320 // Sidebar regions get some extra classes and a common template suggestion.
b6e4708e
J
321 if (strpos($variables['region'], 'sidebar_') === 0) {
322 $variables['classes_array'][] = 'column';
323 $variables['classes_array'][] = 'sidebar';
324 $variables['theme_hook_suggestions'][] = 'region__sidebar';
6b8155aa 325 // Allow a region-specific template to override Zen's region--sidebar.
b6e4708e 326 $variables['theme_hook_suggestions'][] = 'region__' . $variables['region'];
995d309c 327 }
786931f7
J
328 // Use a bare template for the content region.
329 elseif ($variables['region'] == 'content') {
330 $variables['theme_hook_suggestions'][] = 'region__bare';
331 }
94f89279
J
332}
333
334/**
0b1037f4 335 * Override or insert variables into the block templates.
28511ba8 336 *
b6e4708e 337 * @param $variables
0b1037f4 338 * An array of variables to pass to the theme template.
e6f4a124 339 * @param $hook
0b1037f4 340 * The name of the template being rendered ("block" in this case.)
28511ba8 341 */
b6e4708e 342function zen_preprocess_block(&$variables, $hook) {
786931f7
J
343 // Use a bare template for the page's main content.
344 if ($variables['block_html_id'] == 'block-system-main') {
345 $variables['theme_hook_suggestions'][] = 'block__bare';
346 }
347
288001f7 348 // Classes describing the position of the block within the region.
b6e4708e
J
349 if ($variables['block_id'] == 1) {
350 $variables['classes_array'][] = 'first';
288001f7
J
351 }
352 // The last_in_region property is set in zen_page_alter().
b6e4708e
J
353 if (isset($variables['block']->last_in_region)) {
354 $variables['classes_array'][] = 'last';
288001f7 355 }
b6e4708e 356 $variables['classes_array'][] = $variables['block_zebra'];
4e316b5a 357
b6e4708e 358 $variables['title_attributes_array']['class'][] = 'block-title';
3183d194 359}
a3f7ecae
J
360
361/**
362 * Override or insert variables into the block templates.
363 *
b6e4708e 364 * @param $variables
a3f7ecae
J
365 * An array of variables to pass to the theme template.
366 * @param $hook
367 * The name of the template being rendered ("block" in this case.)
368 */
b6e4708e 369function zen_process_block(&$variables, $hook) {
a3f7ecae 370 // Drupal 7 should use a $title variable instead of $block->subject.
b6e4708e 371 $variables['title'] = $variables['block']->subject;
a3f7ecae 372}
288001f7
J
373
374/**
375 * Implements hook_page_alter().
376 *
377 * Look for the last block in the region. This is impossible to determine from
378 * within a preprocess_block function.
379 *
380 * @param $page
381 * Nested array of renderable elements that make up the page.
382 */
383function zen_page_alter(&$page) {
384 // Look in each visible region for blocks.
385 foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) {
386 if (!empty($page[$region])) {
387 // Find the last block in the region.
388 $blocks = array_reverse(element_children($page[$region]));
389 while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) {
390 array_shift($blocks);
391 }
392 if ($blocks) {
393 $page[$region][$blocks[0]]['#block']->last_in_region = TRUE;
394 }
395 }
396 }
397}
e63ff516
J
398
399/**
400 * Implements hook_form_BASE_FORM_ID_alter().
401 *
402 * Prevent user-facing field styling from screwing up node edit forms by
403 * renaming the classes on the node edit form's field wrappers.
404 */
405function zen_form_node_form_alter(&$form, &$form_state, $form_id) {
406 // Remove if #1245218 is backported to D7 core.
407 foreach (array_keys($form) as $item) {
408 if (strpos($item, 'field_') === 0) {
409 if (!empty($form[$item]['#attributes']['class'])) {
410 foreach ($form[$item]['#attributes']['class'] as &$class) {
411 if (strpos($class, 'field-type-') === 0 || strpos($class, 'field-name-') === 0) {
412 // Make the class different from that used in theme_field().
413 $class = 'form-' . $class;
414 }
415 }
416 }
417 }
418 }
419}