diff --git a/themes/bartik/template.php b/themes/bartik/template.php index d523a0a..3b64842 100644 --- a/themes/bartik/template.php +++ b/themes/bartik/template.php @@ -1,6 +1,61 @@ root = &$array; + parent::__construct(&$array); + } + + /** + * Renders the object when used directly with 'print' or 'echo'. + */ + public function __toString() { + return render($this->root); + } +} + +/** + * Check if the element has content. + */ +function has($element) { + if (is_object($element)) { + $element = $element->getArrayCopy(); + } + if (!empty($element['#printed']) && isset($element['#children'])) { + $element = $element['#children']; + } + return !empty($element); +} + +/** + * Page preprocess function. + */ +function bartik_preprocess_page(&$variables) { + global $theme; + + // Gather all render array elements and convert them to RenderArray objects. + foreach (array_keys(system_region_list($theme, REGIONS_VISIBLE)) as $render_key) { + $variables[$render_key] = new RenderArray($variables['page'][$render_key]); + } + foreach (array('title_prefix', 'title_suffix', 'tabs') as $render_key) { + // Save raw copy since RenderArray cannot reference itself. + $variables[$render_key . '_raw'] = $variables[$render_key]; + $variables[$render_key] = new RenderArray($variables[$render_key . '_raw']); + } +} + +/** * Add body classes if certain regions have content. */ function bartik_preprocess_html(&$variables) { diff --git a/themes/bartik/templates/page.tpl.php b/themes/bartik/templates/page.tpl.php index 7b0f990..2b035ab 100644 --- a/themes/bartik/templates/page.tpl.php +++ b/themes/bartik/templates/page.tpl.php @@ -88,31 +88,31 @@