Created
October 16, 2013 03:51
-
-
Save steveoliver/7002428 to your computer and use it in GitHub Desktop.
has_render_content() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks that a render array has content that can be rendered. | |
* | |
* @param $element | |
* The element to check. | |
* | |
* @param $offset | |
* The key of the child to check. | |
* | |
* @return bool | |
* TRUE if the element has access granted and content that can be rendered. | |
*/ | |
function has_render_content($element, $offset) { | |
// Require element and offset. | |
if (!$element || !$offset || empty($element[$offset])) { | |
return FALSE; | |
} | |
// Stop if access is denied. | |
if (isset($element[$offset]['#access']) && !$element[$offset]['#access']) { | |
return FALSE; | |
} | |
// Check for first renderable child. | |
$children = element_get_visible_children($element[$offset]); | |
if (!empty($children)) { | |
$child_checks = array(); | |
foreach ($children as $key) { | |
if (has_render_content($element[$offset], $key)) { | |
$child_checks[$key] = TRUE; | |
continue; | |
} | |
} | |
return !empty($child_checks); | |
} | |
else { | |
// We are checking an element with no renderable children. | |
// i.e. stark.tools in #region sidebar_first | |
// How do we know this element should be shown? | |
// | |
return !empty($element[$offset]['#children']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment