4 * Contains theme override functions and preprocess functions for the Zen theme.
6 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
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
14 // Auto-rebuild the theme registry during theme development.
15 if (theme_get_setting('zen_rebuild_registry')) {
16 // Rebuild .info data.
17 system_rebuild_theme_data();
18 // Rebuild theme registry.
19 drupal_theme_rebuild();
24 * Implements HOOK_theme().
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);
32 * Return a themed breadcrumb trail.
35 * An array containing the breadcrumb links.
37 * A string containing the breadcrumb output.
39 function zen_breadcrumb($variables) {
40 $breadcrumb = $variables['breadcrumb'];
41 // Determine if we are to display the breadcrumb.
42 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
43 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
45 // Optionally get rid of the homepage link.
46 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
47 if (!$show_breadcrumb_home) {
48 array_shift($breadcrumb);
51 // Return the breadcrumb with separators.
52 if (!empty($breadcrumb)) {
53 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
54 $trailing_separator = $title = '';
55 if (theme_get_setting('zen_breadcrumb_title')) {
56 $item = menu_get_item();
57 if (!empty($item['tab_parent'])) {
58 // If we are on a non-default tab, use the tab's title.
59 $title = check_plain($item['title']);
62 $title = drupal_get_title();
65 $trailing_separator = $breadcrumb_separator;
68 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
69 $trailing_separator = $breadcrumb_separator;
72 // Provide a navigational heading to give context for breadcrumb links to
73 // screen-reader users. Make the heading invisible with .element-invisible.
74 $heading = '<h2 class="element-invisible">' .
t('You are here') .
'</h2>';
76 return $heading .
'<div class="breadcrumb">' .
implode($breadcrumb_separator, $breadcrumb) .
$trailing_separator .
$title .
'</div>';
79 // Otherwise, return an empty string.
84 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
86 function zen_menu_local_tasks(&$variables) {
89 if (!empty($variables['primary'])) {
90 $variables['primary']['#prefix'] = '<h2 class="element-invisible">' .
t('Primary tabs') .
'</h2>';
91 $variables['primary']['#prefix'] .
= '<ul class="tabs primary clearfix">';
92 $variables['primary']['#suffix'] = '</ul>';
93 $output .
= drupal_render($variables['primary']);
95 if (!empty($variables['secondary'])) {
96 $variables['secondary']['#prefix'] = '<h2 class="element-invisible">' .
t('Secondary tabs') .
'</h2>';
97 $variables['secondary']['#prefix'] .
= '<ul class="tabs secondary clearfix">';
98 $variables['secondary']['#suffix'] = '</ul>';
99 $output .
= drupal_render($variables['secondary']);
106 * Override or insert variables into theme_menu_local_task().
108 function zen_preprocess_menu_local_task(&$variables) {
109 $link =& $variables['element']['#link'];
111 // If the link does not contain HTML already, check_plain() it now.
112 // After we set 'html'=TRUE the link will not be sanitized by l().
113 if (empty($link['localized_options']['html'])) {
114 $link['title'] = check_plain($link['title']);
116 $link['localized_options']['html'] = TRUE
;
117 $link['title'] = '<span class="tab">' .
$link['title'] .
'</span>';
121 * Adds conditional CSS from the .info file.
123 * Copy of conditional_styles_preprocess_html().
125 function zen_add_conditional_styles() {
126 // Make a list of base themes and the current theme.
127 $themes = $GLOBALS['base_theme_info'];
128 $themes[] = $GLOBALS['theme_info'];
129 foreach (array_keys($themes) as
$key) {
130 $theme_path = dirname($themes[$key]->filename
) .
'/';
131 if (isset($themes[$key]->info
['stylesheets-conditional'])) {
132 foreach (array_keys($themes[$key]->info
['stylesheets-conditional']) as
$condition) {
133 foreach (array_keys($themes[$key]->info
['stylesheets-conditional'][$condition]) as
$media) {
134 foreach ($themes[$key]->info
['stylesheets-conditional'][$condition][$media] as
$stylesheet) {
135 // Add each conditional stylesheet.
137 $theme_path .
$stylesheet,
139 'group' => CSS_THEME
,
144 'every_page' => TRUE
,
155 * Override or insert variables into the html template.
158 * An array of variables to pass to the theme template.
160 * The name of the template being rendered ("html" in this case.)
162 function zen_preprocess_html(&$vars, $hook) {
163 // If the user is silly and enables Zen as the theme, add some styles.
164 if ($GLOBALS['theme'] == 'zen') {
165 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.zen.inc';
166 _zen_preprocess_html($vars, $hook);
168 elseif (!module_exists('conditional_styles')) {
169 zen_add_conditional_styles();
172 // Classes for body element. Allows advanced theming based on context
173 // (home page, node of certain type, etc.)
174 if (!$vars['is_front']) {
175 // Add unique class for each page.
176 $path = drupal_get_path_alias($_GET['q']);
177 // Add unique class for each website section.
178 list($section, ) = explode('/', $path, 2);
179 if (arg(0) == 'node') {
180 if (arg(1) == 'add') {
181 $section = 'node-add';
183 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
184 $section = 'node-' .
arg(2);
187 $vars['classes_array'][] = drupal_html_class('section-' .
$section);
189 if (theme_get_setting('zen_wireframes')) {
190 $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
192 // Store the menu item since it has some useful information.
193 $vars['menu_item'] = menu_get_item();
194 switch ($vars['menu_item']['page_callback']) {
196 // Is this a Views page?
197 $vars['classes_array'][] = 'page-views';
199 case
'page_manager_page_execute':
200 case
'page_manager_node_view':
201 case
'page_manager_contact_site':
202 // Is this a Panels page?
203 $vars['classes_array'][] = 'page-panels';
209 * Override or insert variables into the maintenance page template.
212 * An array of variables to pass to the theme template.
214 * The name of the template being rendered ("maintenance_page" in this case.)
216 function zen_preprocess_maintenance_page(&$vars, $hook) {
217 // If Zen is the maintenance theme, add some styles.
218 if ($GLOBALS['theme'] == 'zen') {
219 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.zen.inc';
220 _zen_preprocess_html($vars, $hook);
222 elseif (!module_exists('conditional_styles')) {
223 zen_add_conditional_styles();
228 * Override or insert variables into the node templates.
231 * An array of variables to pass to the theme template.
233 * The name of the template being rendered ("node" in this case.)
235 function zen_preprocess_node(&$vars, $hook) {
236 if (isset($vars['node_title'])) {
237 // $node_title is idiotic. Fixed in Alpha 4.
238 $vars['title'] = $vars['node_title'];
241 // Special classes for nodes.
242 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
243 $vars['classes_array'][] = drupal_html_class('node-type-' .
$vars['type']);
244 if ($vars['promote']) {
245 $vars['classes_array'][] = 'node-promoted';
247 if ($vars['sticky']) {
248 $vars['classes_array'][] = 'node-sticky';
250 if (!$vars['status']) {
251 $vars['classes_array'][] = 'node-unpublished';
252 $vars['unpublished'] = TRUE
;
255 $vars['unpublished'] = FALSE
;
257 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid
) {
258 $vars['classes_array'][] = 'node-by-viewer'; // Node is authored by current user.
260 if ($vars['teaser']) {
261 $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser.
263 if (isset($vars['preview'])) {
264 $vars['classes_array'][] = 'node-preview';
267 $vars['title_attributes_array']['class'][] = 'node-title';
271 * Override or insert variables into the comment templates.
274 * An array of variables to pass to the theme template.
276 * The name of the template being rendered ("comment" in this case.)
278 function zen_preprocess_comment(&$vars, $hook) {
279 // If comment subjects are disabled, don't display them.
280 if (variable_get('comment_subject_field_' .
$vars['node']->type
, 1) == 0) {
285 if ($vars['id'] == 1) {
286 $vars['classes_array'][] = 'first';
288 if ($vars['id'] == $vars['node']->comment_count
) {
289 $vars['classes_array'][] = 'last';
291 $vars['classes_array'][] = $vars['zebra'];
293 $vars['title_attributes_array']['class'][] = 'comment-title';
297 * Preprocess variables for region.tpl.php
299 * Prepare the values passed to the theme_region function to be passed into a
300 * pluggable template engine. Uses the region name to generate a template file
301 * suggestions. If none are found, the default region.tpl.php is used.
303 * @see region.tpl.php
305 function zen_preprocess_region(&$vars, $hook) {
306 // Sidebar regions get some extra classes and a common template suggestion.
307 if (strpos($vars['region'], 'sidebar_') === 0) {
308 $vars['classes_array'][] = 'column';
309 $vars['classes_array'][] = 'sidebar';
310 $vars['theme_hook_suggestions'][] = 'region__sidebar';
311 // Allow a region-specific template to override Zen's region--sidebar.
312 $vars['theme_hook_suggestions'][] = 'region__' .
$vars['region'];
317 * Override or insert variables into the block templates.
320 * An array of variables to pass to the theme template.
322 * The name of the template being rendered ("block" in this case.)
324 function zen_preprocess_block(&$vars, $hook) {
325 // Special classes for blocks.
326 $vars['classes_array'][] = 'region-' .
$vars['block_zebra'];
327 $vars['classes_array'][] = 'region-count-' .
$vars['block_id'];
329 $vars['title_attributes_array']['class'][] = 'block-title';
333 * Override or insert variables into the block templates.
336 * An array of variables to pass to the theme template.
338 * The name of the template being rendered ("block" in this case.)
340 function zen_process_block(&$vars, $hook) {
341 // Drupal 7 should use a $title variable instead of $block->subject.
342 $vars['title'] = $vars['block']->subject
;