summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnAlbin2009-10-15 18:28:58 +0000
committerJohnAlbin2009-10-15 18:28:58 +0000
commitd212bfc9e4680d2359ea756d88c5008d3decb731 (patch)
tree51c2bd50dccea99efb9cdf39e5fb67c85c4de736
parentfdb523d3e75e322a2140aa7aacf6713a6e36f582 (diff)
Three inter-related items in one commit:
- Added $classes and $classes_array to all templates, not just Zen's templates. - Renamed page.tpl's $body_classes and $body_classes_array to $classes and $classes_array - #564068: Views classes are missing from $classes variable
-rw-r--r--CHANGELOG.txt3
-rw-r--r--template.php77
-rw-r--r--templates/maintenance-page.tpl.php2
-rw-r--r--templates/page.tpl.php10
-rw-r--r--zen-internals/template.comment.inc19
5 files changed, 58 insertions, 53 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 24dc489..4cdc3e8 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -2,6 +2,9 @@
Zen 6.x-2.x-dev, xxxx-xx-xx (development release)
------------------------
+- Added $classes and $classes_array to all templates, not just Zen's templates.
+- Renamed page.tpl's $body_classes and $body_classes_array to $classes and $classes_array
+- #564068: Views classes are missing from $classes variable
- Simplified header, content_top, content_bottom, navbar, and footer region markup
- Add region.tpl.php template
- Render $edit_links_array in zen_process_block
diff --git a/template.php b/template.php
index 9924d44..e15ee06 100644
--- a/template.php
+++ b/template.php
@@ -126,6 +126,28 @@ function zen_blocks($region) {
}
/**
+ * Override or insert variables into templates before other preprocess functions have run.
+ *
+ * @param $vars
+ * An array of variables to pass to the theme template.
+ * @param $hook
+ * The name of the template being rendered.
+ */
+function zen_preprocess(&$vars, $hook) {
+ // In D6, the page.tpl uses a different variable name to hold the classes.
+ $key = ($hook == 'page' || $hook == 'maintenance_page') ? 'body_classes' : 'classes';
+
+ // Create a D7-standard classes_array variable.
+ if (array_key_exists($key, $vars)) {
+ $vars['classes_array'] = explode(' ', $vars[$key]);
+ unset($vars[$key]);
+ }
+ else {
+ $vars['classes_array'] = array($hook);
+ }
+}
+
+/**
* Override or insert variables into the page templates.
*
* @param $vars
@@ -146,15 +168,14 @@ function zen_preprocess_page(&$vars, $hook) {
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
- $classes = explode(' ', $vars['body_classes']);
// Remove the mostly useless page-ARG0 class.
- if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $classes)) {
- unset($classes[$index]);
+ if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $vars['classes_array'])) {
+ unset($vars['classes_array'][$index]);
}
if (!$vars['is_front']) {
// Add unique class for each page.
$path = drupal_get_path_alias($_GET['q']);
- $classes[] = zen_id_safe('page-' . $path);
+ $vars['classes_array'][] = zen_id_safe('page-' . $path);
// Add unique class for each website section.
list($section, ) = explode('/', $path, 2);
if (arg(0) == 'node') {
@@ -165,23 +186,21 @@ function zen_preprocess_page(&$vars, $hook) {
$section = 'node-' . arg(2);
}
}
- $classes[] = zen_id_safe('section-' . $section);
+ $vars['classes_array'][] = zen_id_safe('section-' . $section);
}
if (theme_get_setting('zen_wireframes')) {
- $classes[] = 'with-wireframes'; // Optionally add the wireframes style.
+ $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
}
// Add new sidebar classes in addition to Drupal core's sidebar-* classes.
// This provides some backwards compatibility with Zen 6.x-1.x themes.
if ($vars['layout'] != 'both') {
$new_layout = ($vars['layout'] == 'left') ? 'first' : 'second';
- if (array_search('sidebar-' . $vars['layout'], $classes)) {
- $classes[] = 'sidebar-' . $new_layout;
+ if (array_search('sidebar-' . $vars['layout'], $vars['classes_array'])) {
+ $vars['classes_array'][] = 'sidebar-' . $new_layout;
}
// Replace core's $layout variable with our naming of sidebars.
$vars['layout'] = $new_layout;
}
- $vars['body_classes_array'] = $classes;
- $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces.
}
/**
@@ -243,32 +262,30 @@ function zen_preprocess_node(&$vars, $hook) {
$vars['user_picture'] = $vars['picture'];
// Special classes for nodes.
- $classes = array('node');
// Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
- $classes[] = zen_id_safe('node-type-' . $vars['type']);
+ $vars['classes_array'][] = zen_id_safe('node-type-' . $vars['type']);
if ($vars['promote']) {
$vars['classes_array'][] = 'node-promoted';
}
if ($vars['sticky']) {
- $classes[] = 'node-sticky';
+ $vars['classes_array'][] = 'node-sticky';
}
if (!$vars['status']) {
- $classes[] = 'node-unpublished';
+ $vars['classes_array'][] = 'node-unpublished';
$vars['unpublished'] = TRUE;
}
else {
$vars['unpublished'] = FALSE;
}
if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
- $classes[] = 'node-mine'; // Node is authored by current user.
+ $vars['classes_array'][] = 'node-mine'; // Node is authored by current user.
}
if ($vars['teaser']) {
- $classes[] = 'node-teaser'; // Node is displayed as teaser.
+ $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser.
}
if (isset($vars['preview'])) {
$vars['classes_array'][] = 'node-preview';
}
- $vars['classes_array'] = $classes;
}
/**
@@ -318,22 +335,18 @@ function zen_preprocess_block(&$vars, $hook) {
$block = $vars['block'];
// Special classes for blocks.
- $classes = array('block');
- $classes[] = 'block-' . $block->module;
- $classes[] = 'region-' . $vars['block_zebra'];
- $classes[] = $vars['zebra'];
- $classes[] = 'region-count-' . $vars['block_id'];
- $classes[] = 'count-' . $vars['id'];
+ $vars['classes_array'][] = 'block-' . $block->module;
+ $vars['classes_array'][] = 'region-' . $vars['block_zebra'];
+ $vars['classes_array'][] = $vars['zebra'];
+ $vars['classes_array'][] = 'region-count-' . $vars['block_id'];
+ $vars['classes_array'][] = 'count-' . $vars['id'];
$vars['edit_links_array'] = array();
if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
include_once './' . _zen_path() . '/zen-internals/template.block-editing.inc';
zen_preprocess_block_editing($vars, $hook);
- $classes[] = 'with-block-editing';
+ $vars['classes_array'][] = 'with-block-editing';
}
-
- // Render block classes.
- $vars['classes_array'] = $classes;
}
/**
@@ -345,15 +358,7 @@ function zen_preprocess_block(&$vars, $hook) {
* The name of the template being rendered.
*/
function zen_process(&$vars, $hook) {
- switch ($hook) {
- case 'page':
- case 'maintenance_page':
- $vars['body_classes'] = !empty($vars['body_classes_array']) ? implode(' ', $vars['body_classes_array']) : '';
- break;
- default:
- $vars['classes'] = !empty($vars['classes_array']) ? implode(' ', $vars['classes_array']) : '';
- break;
- }
+ $vars['classes'] = implode(' ', $vars['classes_array']);
}
/**
diff --git a/templates/maintenance-page.tpl.php b/templates/maintenance-page.tpl.php
index cb9141d..7d34b39 100644
--- a/templates/maintenance-page.tpl.php
+++ b/templates/maintenance-page.tpl.php
@@ -23,7 +23,7 @@
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
-<body class="<?php print $body_classes; ?>">
+<body class="<?php print $classes; ?>">
<div id="page"><div id="page-inner">
diff --git a/templates/page.tpl.php b/templates/page.tpl.php
index b0d86c3..11a7160 100644
--- a/templates/page.tpl.php
+++ b/templates/page.tpl.php
@@ -13,8 +13,8 @@
* - $css: An array of CSS files for the current page.
* - $directory: The directory the template is located in, e.g. modules/system
* or themes/garland.
- * - $body_classes_array: Array of the body classes. It is flattened
- * into a string within the variable $classes.
+ * - $classes_array: Array of the body classes. It is flattened into a string
+ * within the variable $classes.
* - $is_front: TRUE if the current page is the front page. Used to toggle the mission statement.
* - $logged_in: TRUE if the user is registered and signed in.
* - $is_admin: TRUE if the user has permission to access administration pages.
@@ -29,10 +29,10 @@
* - $styles: Style tags necessary to import all CSS files for the page.
* - $scripts: Script tags necessary to load the JavaScript files and settings
* for the page.
- * - $body_classes: String of classes that can be used to style contextually through
+ * - $classes: String of classes that can be used to style contextually through
* CSS. It should be placed within the <body> tag. When selecting through CSS
* it's recommended that you use the body tag, e.g., "body.front". It can be
- * manipulated through the variable $body_classes_array from preprocess functions.
+ * manipulated through the variable $classes_array from preprocess functions.
* The default values can be one or more of the following:
* - front: Page is the home page.
* - not-front: Page is not the home page.
@@ -96,7 +96,7 @@
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
-<body class="<?php print $body_classes; ?>">
+<body class="<?php print $classes; ?>">
<div id="page"><div id="page-inner">
diff --git a/zen-internals/template.comment.inc b/zen-internals/template.comment.inc
index 5fb6d72..d312078 100644
--- a/zen-internals/template.comment.inc
+++ b/zen-internals/template.comment.inc
@@ -24,32 +24,29 @@ function _zen_preprocess_comment(&$vars, $hook) {
}
// Special classes for comments.
- $classes = array('comment');
if ($vars['comment']->new) {
- $classes[] = 'comment-new';
+ $vars['classes_array'][] = 'comment-new';
}
- $classes[] = $vars['status'];
- $classes[] = $vars['zebra'];
+ $vars['classes_array'][] = $vars['status'];
+ $vars['classes_array'][] = $vars['zebra'];
if ($vars['id'] == 1) {
- $classes[] = 'first';
+ $vars['classes_array'][] = 'first';
}
if ($vars['id'] == $vars['node']->comment_count) {
- $classes[] = 'last';
+ $vars['classes_array'][] = 'last';
}
if ($vars['comment']->uid == 0) {
// Comment is by an anonymous user.
- $classes[] = 'comment-by-anon';
+ $vars['classes_array'][] = 'comment-by-anon';
}
else {
if ($vars['comment']->uid == $vars['node']->uid) {
// Comment is by the node author.
- $classes[] = 'comment-by-author';
+ $vars['classes_array'][] = 'comment-by-author';
}
if ($vars['comment']->uid == $GLOBALS['user']->uid) {
// Comment was posted by current user.
- $classes[] = 'comment-mine';
+ $vars['classes_array'][] = 'comment-mine';
}
}
- $vars['classes_array'] = $classes;
- $vars['classes'] = implode(' ', $classes);
}