summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-06-18 21:19:02 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-06-18 21:19:02 +0000
commit4d202669af4d2cc64244d70fe064aef6c50c1b23 (patch)
tree4918e7f5c8c3c1ee8246131ae9eb413ab33d7aef /includes
parent19d10a4e908810a53db4a08ed386c4cf1be935f1 (diff)
downloadbrdo-4d202669af4d2cc64244d70fe064aef6c50c1b23.tar.gz
brdo-4d202669af4d2cc64244d70fe064aef6c50c1b23.tar.bz2
#455844 by yched, JohnAlbin, moshe weitzman, Frando, et al: Allow more granular theming of drupal_render()ed elements.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc50
-rw-r--r--includes/theme.inc43
2 files changed, 76 insertions, 17 deletions
diff --git a/includes/common.inc b/includes/common.inc
index a926d019d..a1996a189 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3748,6 +3748,56 @@ function drupal_render_children(&$element, $children_keys = NULL) {
}
/**
+ * Render and print an element.
+ *
+ * This function renders an element using drupal_render() and then prints out
+ * the rendered output. The top level element is always rendered and printed
+ * even if hide() had been previously used on it.
+ *
+ * Any nested elements are only printed if they haven't been printed before or
+ * if they have been re-enabled with show(). If the element is a string instead
+ * of a renderable array it is also printed.
+ *
+ * @see drupal_render()
+ * @see show()
+ * @see hide()
+ */
+function render(&$element) {
+ if (is_array($element)) {
+ show($element);
+ print drupal_render($element);
+ }
+ else {
+ print $element;
+ }
+}
+
+/**
+ * Hide an element from later rendering.
+ *
+ * @see render()
+ * @see show()
+ */
+function hide(&$element) {
+ $element['#printed'] = TRUE;
+ return $element;
+}
+
+/**
+ * Show a hidden or already printed element from later rendering.
+ *
+ * Alternatively, render($element) could be used which automatically shows the
+ * element while rendering and printing it.
+ *
+ * @see render()
+ * @see hide()
+ */
+function show(&$element) {
+ $element['#printed'] = FALSE;
+ return $element;
+}
+
+/**
* Function used by uasort to sort structured arrays by weight.
*/
function element_sort($a, $b) {
diff --git a/includes/theme.inc b/includes/theme.inc
index 59561c560..7558d2b1d 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -1886,7 +1886,7 @@ function template_process(&$variables, $hook) {
}
/**
- * Process variables for page.tpl.php
+ * Preprocess variables for page.tpl.php
*
* Most themes utilize their own copy of page.tpl.php. The default is located
* inside "modules/system/page.tpl.php". Look in there for the full list of
@@ -1897,12 +1897,9 @@ function template_process(&$variables, $hook) {
*
* Any changes to variables in this preprocessor should also be changed inside
* template_preprocess_maintenance_page() to keep all of them consistent.
- *
- * The $variables array contains two keys:
- * - 'page': the fully decorated page.
- * - 'content': the content of the page, already rendered.
- *
+ *
* @see drupal_render_page
+ * @see template_process_page
* @see page.tpl.php
*/
function template_preprocess_page(&$variables) {
@@ -1910,11 +1907,6 @@ function template_preprocess_page(&$variables) {
$variables['show_blocks'] = $variables['page']['#show_blocks'];
$variables['show_messages'] = $variables['page']['#show_messages'];
- // Render each region into top level variables.
- foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
- $variables[$region_key] = empty($variables['page'][$region_key]) ? '' : drupal_render($variables['page'][$region_key]);
- }
-
// Add favicon.
if (theme_get_setting('toggle_favicon')) {
$favicon = theme_get_setting('favicon');
@@ -1928,10 +1920,10 @@ function template_preprocess_page(&$variables) {
// Set up layout variable.
$variables['layout'] = 'none';
- if (!empty($variables['left'])) {
+ if (!empty($variables['page']['left'])) {
$variables['layout'] = 'left';
}
- if (!empty($variables['right'])) {
+ if (!empty($variables['page']['right'])) {
$variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
}
@@ -1950,7 +1942,6 @@ function template_preprocess_page(&$variables) {
$variables['front_page'] = url();
$variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());
$variables['feed_icons'] = drupal_get_feeds();
- $variables['head'] = drupal_get_html_head();
$variables['language'] = $GLOBALS['language'];
$variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
$variables['logo'] = theme_get_setting('logo');
@@ -1960,9 +1951,6 @@ function template_preprocess_page(&$variables) {
$variables['search_box'] = (theme_get_setting('toggle_search') ? drupal_render(drupal_get_form('search_theme_form')) : '');
$variables['site_name'] = (theme_get_setting('toggle_name') ? filter_xss_admin(variable_get('site_name', 'Drupal')) : '');
$variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');
- $variables['css'] = drupal_add_css();
- $variables['styles'] = drupal_get_css();
- $variables['scripts'] = drupal_get_js();
$variables['tabs'] = theme('menu_local_tasks');
$variables['title'] = drupal_get_title();
// RDFa allows annotation of XHTML pages with RDF data, while GRDDL provides
@@ -2014,6 +2002,27 @@ function template_preprocess_page(&$variables) {
$variables['classes_array'][] = 'one-sidebar sidebar-' . $variables['layout'];
}
}
+/**
+ * Process variables for page.tpl.php
+ *
+ * Perform final addition and modification of variables before passing into
+ * the template. To customize these variables, call drupal_render() on elements
+ * in $variables['page'] during THEME_preprocess_page().
+ *
+ * @see template_preprocess_page()
+ * @see page.tpl.php
+ */
+function template_process_page(&$variables) {
+ // Render each region into top level variables.
+ foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
+ $variables[$region_key] = drupal_render($variables['page'][$region_key]);
+ }
+
+ $variables['head'] = drupal_get_html_head();
+ $variables['css'] = drupal_add_css();
+ $variables['styles'] = drupal_get_css();
+ $variables['scripts'] = drupal_get_js();
+}
/**
* Generate an array of page template suggestions.