Skip to content

Instantly share code, notes, and snippets.

@steveoliver
Created October 16, 2013 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveoliver/7002428 to your computer and use it in GitHub Desktop.
Save steveoliver/7002428 to your computer and use it in GitHub Desktop.
has_render_content() function
/**
* 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