summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnAlbin2009-11-03 18:27:44 +0000
committerJohnAlbin2009-11-03 18:27:44 +0000
commit9dfc7d9f632853dc3292f015547667d451ae837e (patch)
tree9a6220fabd72d898eb229a9ea1dc2dc7798926bd
parent16b8d1be20a3c7e18e9980fc2cc074d9f8e38025 (diff)
#621798: Change sidebar variables to be RTL friendly and $shows_blocks compatible
-rw-r--r--CHANGELOG.txt1
-rw-r--r--STARTERKIT/STARTERKIT.info.txt4
-rw-r--r--template.php90
-rw-r--r--templates/maintenance-page.tpl.php8
-rw-r--r--templates/page.tpl.php12
-rw-r--r--zen-internals/template.theme-registry.inc6
-rw-r--r--zen.info4
7 files changed, 90 insertions, 35 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 9557173..5999f61 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -2,6 +2,7 @@
Zen 6.x-2.x-dev, xxxx-xx-xx (development release)
------------------------
+- #621798: Change sidebar variables to be RTL friendly and $shows_blocks compatible
- #547696: Update node.tpl to use ideas from D7
- #620794: Update block.tpl to use ideas from D7
- #548994: Update comment.tpl and comment-wrapper.tpl to use ideas from D7
diff --git a/STARTERKIT/STARTERKIT.info.txt b/STARTERKIT/STARTERKIT.info.txt
index fd56732..eb6e283 100644
--- a/STARTERKIT/STARTERKIT.info.txt
+++ b/STARTERKIT/STARTERKIT.info.txt
@@ -60,8 +60,8 @@ conditional-stylesheets[if lte IE 6][all][] = css/ie6.css
; To add a new region, copy Zen's page.tpl.php to your sub-theme's directory,
; add a line line to this file, and then add the new variable to your
; page.tpl.php template.
-regions[left] = first sidebar
-regions[right] = second sidebar
+regions[sidebar_first] = first sidebar
+regions[sidebar_second] = second sidebar
regions[navbar] = navigation bar
regions[content_top] = content top
regions[content_bottom] = content bottom
diff --git a/template.php b/template.php
index cf901d3..51f6a32 100644
--- a/template.php
+++ b/template.php
@@ -103,26 +103,61 @@ function zen_menu_local_tasks() {
*
* @param $region
* Which set of blocks to retrieve.
+ * @param $show_blocks
+ * A boolean to determine whether to render sidebar regions or not. Should be
+ * the same value as passed to theme_page.
* @return
* A string containing the themed blocks for this region.
+ *
+ * @see zen_show_blocks_discovery()
*/
-function zen_blocks($region) {
- $output = '';
+function zen_blocks($region, $show_blocks = NULL) {
+ // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call
+ // theme('blocks', NULL, $show_blocks) so that this function can remember the
+ // value on later calls.
+ static $render_sidebars = TRUE;
+ if (!is_null($show_blocks)) {
+ $render_sidebars = $show_blocks;
+ }
- if ($list = block_list($region)) {
- foreach ($list as $key => $block) {
- // $key == module_delta
- $output .= theme('block', $block);
+ // If zen_blocks was called with a NULL region, its likely we were just
+ // setting the $render_sidebars static variable.
+ if ($region) {
+ $output = '';
+
+ // If $renders_sidebars is FALSE, don't render any region whose name begins
+ // with "sidebar_".
+ if (($render_sidebars || (strpos($region, 'sidebar_') !== 0)) && ($list = block_list($region))) {
+ foreach ($list as $key => $block) {
+ // $key == module_delta
+ $output .= theme('block', $block);
+ }
}
- }
- // Add any content assigned to this region through drupal_set_content() calls.
- $output .= drupal_get_content($region);
+ // Add any content assigned to this region through drupal_set_content() calls.
+ $output .= drupal_get_content($region);
- $elements['#children'] = $output;
- $elements['#region'] = $region;
+ $elements['#children'] = $output;
+ $elements['#region'] = $region;
- return $output ? theme('region', $elements) : '';
+ return $output ? theme('region', $elements) : '';
+ }
+}
+
+/**
+ * Examine the $show_blocks variable before template_preprocess_page() is called.
+ *
+ * @param $vars
+ * An array of variables to pass to the page template.
+ *
+ * @see zen_blocks()
+ */
+function zen_show_blocks_discovery(&$vars) {
+ if ($vars['show_blocks'] == FALSE) {
+ // Allow zen_blocks() to statically cache the $show_blocks variable. A TRUE
+ // value is assumed, so we only need to override when $show_blocks is FALSE.
+ theme('blocks', NULL, FALSE);
+ }
}
/**
@@ -195,15 +230,30 @@ function zen_preprocess_page(&$vars, $hook) {
if (theme_get_setting('zen_wireframes')) {
$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'], $vars['classes_array'])) {
- $vars['classes_array'][] = 'sidebar-' . $new_layout;
+ // We need to re-do the $layout and body classes because
+ // template_preprocess_page() assumes sidebars are named 'left' and 'right'.
+ $vars['layout'] = 'none';
+ if (!empty($vars['sidebar_first'])) {
+ $vars['layout'] = 'first';
+ }
+ if (!empty($vars['sidebar_second'])) {
+ $vars['layout'] = ($vars['layout'] == 'first') ? 'both' : 'second';
+ }
+ // If the layout is 'none', then template_preprocess_page() will already have
+ // set a 'no-sidebars' class since it won't find a 'left' or 'right' sidebar.
+ if ($vars['layout'] != 'none') {
+ // Remove the incorrect 'no-sidebars' class.
+ if ($index = array_search('no-sidebars', $vars['classes_array'])) {
+ unset($vars['classes_array'][$index]);
+ }
+ // Set the proper layout body classes.
+ if ($vars['layout'] == 'both') {
+ $vars['classes_array'][] = 'two-sidebars';
+ }
+ else {
+ $vars['classes_array'][] = 'one-sidebar';
+ $vars['classes_array'][] = 'sidebar-' . $vars['layout'];
}
- // Replace core's $layout variable with our naming of sidebars.
- $vars['layout'] = $new_layout;
}
}
diff --git a/templates/maintenance-page.tpl.php b/templates/maintenance-page.tpl.php
index 7d34b39..ee4774e 100644
--- a/templates/maintenance-page.tpl.php
+++ b/templates/maintenance-page.tpl.php
@@ -88,15 +88,15 @@
</div> <!-- /#navbar -->
<?php endif; ?>
- <?php if ($left): ?>
+ <?php if ($sidebar_first): ?>
<div id="sidebar-first"><div id="sidebar-first-inner" class="region region-sidebar-first">
- <?php print $left; ?>
+ <?php print $sidebar_first; ?>
</div></div> <!-- /#sidebar-first-inner, /#sidebar-first -->
<?php endif; ?>
- <?php if ($right): ?>
+ <?php if ($sidebar_second): ?>
<div id="sidebar-second"><div id="sidebar-second-inner" class="region region-sidebar-second">
- <?php print $right; ?>
+ <?php print $sidebar_second; ?>
</div></div> <!-- /#sidebar-second-inner, /#sidebar-second -->
<?php endif; ?>
diff --git a/templates/page.tpl.php b/templates/page.tpl.php
index 02a245c..910c966 100644
--- a/templates/page.tpl.php
+++ b/templates/page.tpl.php
@@ -72,8 +72,8 @@
* - $help: Dynamic help text, mostly for admin pages.
* - $content: The main content of the current page.
* - $feed_icons: A string of all feed icons for the current page.
- * - $left: The HTML for the first sidebar.
- * - $right: The HTML for the second sidebar.
+ * - $sidebar_first: The HTML for the first sidebar.
+ * - $sidebar_second: The HTML for the second sidebar.
*
* Footer/closing data:
* - $footer_message: The footer message as defined in the admin settings.
@@ -195,15 +195,15 @@
</div> <!-- /#navbar -->
<?php endif; ?>
- <?php if ($left): ?>
+ <?php if ($sidebar_first): ?>
<div id="sidebar-first"><div id="sidebar-first-inner" class="region region-sidebar-first">
- <?php print $left; ?>
+ <?php print $sidebar_first; ?>
</div></div> <!-- /#sidebar-first-inner, /#sidebar-first -->
<?php endif; ?>
- <?php if ($right): ?>
+ <?php if ($sidebar_second): ?>
<div id="sidebar-second"><div id="sidebar-second-inner" class="region region-sidebar-second">
- <?php print $right; ?>
+ <?php print $sidebar_second; ?>
</div></div> <!-- /#sidebar-second-inner, /#sidebar-second -->
<?php endif; ?>
diff --git a/zen-internals/template.theme-registry.inc b/zen-internals/template.theme-registry.inc
index ea7a860..8cb45fe 100644
--- a/zen-internals/template.theme-registry.inc
+++ b/zen-internals/template.theme-registry.inc
@@ -60,8 +60,12 @@ function _zen_theme(&$existing, $type, $theme, $path) {
}
}
- // The base theme registers region.tpl.php
+ // Manipulations only to be done by the base theme.
if ($theme == 'zen') {
+ // Insert zen_show_blocks_discovery() before template_preprocess_page().
+ $existing['page']['preprocess functions'] = array_merge(array('zen_show_blocks_discovery'), $existing['page']['preprocess functions']);
+
+ // The base theme registers region.tpl.php.
return array(
'region' => array(
'arguments' => array('elements' => NULL),
diff --git a/zen.info b/zen.info
index 84143f4..201edeb 100644
--- a/zen.info
+++ b/zen.info
@@ -8,8 +8,8 @@ screenshot = zen-internals/screenshot.png
core = 6.x
engine = phptemplate
-regions[left] = first sidebar
-regions[right] = second sidebar
+regions[sidebar_first] = first sidebar
+regions[sidebar_second] = second sidebar
regions[navbar] = navigation bar
regions[content_top] = content top
regions[content_bottom] = content bottom