core/includes/common.inc | 16 ++++++++++++++++ core/themes/bartik/bartik.theme | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index e66261e..fcb09bd 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -986,6 +986,22 @@ function drupal_render_children(&$element, $children_keys = NULL) { } /** + * Checks if the specified element is empty. + * + * @param array $elements + * A render array. + * @param string $key + * The key of the child element to check the emptiness of. + * + * @return bool + * Whether the child of the render array with key $key is empty. If no child + * exists at that key, it is also considered empty. + */ +function element_is_empty(array $elements, $key) { + return !isset($elements[$key]) || Element::isEmpty($elements[$key]); +} + +/** * Renders an element. * * This function renders an element. The top level element is shown with show() diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index db51153..a1aff15 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -16,14 +16,14 @@ */ function bartik_preprocess_html(&$variables) { // Add information about the number of sidebars. - if (isset($variables['page']['sidebar_first']) && isset($variables['page']['sidebar_second']) && !Element::isEmpty($variables['page']['sidebar_first']) && !Element::isEmpty($variables['page']['sidebar_second'])) { + if (!element_is_empty($variables['page'], 'sidebar_first') && !element_is_empty($variables['page'], 'sidebar_second')) { $variables['attributes']['class'][] = 'layout-two-sidebars'; } - elseif (isset($variables['page']['sidebar_first']) && !Element::isEmpty($variables['page']['sidebar_first'])) { + elseif (!element_is_empty($variables['page'], 'sidebar_first')) { $variables['attributes']['class'][] = 'layout-one-sidebar'; $variables['attributes']['class'][] = 'layout-sidebar-first'; } - elseif (isset($variables['page']['sidebar_second']) && !Element::isEmpty($variables['page']['sidebar_second'])) { + elseif (!element_is_empty($variables['page'], 'sidebar_second')) { $variables['attributes']['class'][] = 'layout-one-sidebar'; $variables['attributes']['class'][] = 'layout-sidebar-second'; } @@ -31,7 +31,7 @@ function bartik_preprocess_html(&$variables) { $variables['attributes']['class'][] = 'layout-no-sidebars'; } - if (isset($variables['page']['featured_top']) && !Element::isEmpty($variables['page']['featured_top'])) { + if (!element_is_empty($variables['page'], 'featured_top')) { $variables['attributes']['class'][] = 'has-featured-top'; }