You are here

public static function Container::preRenderContainer in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Container.php \Drupal\Core\Render\Element\Container::preRenderContainer()
  2. 10 core/lib/Drupal/Core/Render/Element/Container.php \Drupal\Core\Render\Element\Container::preRenderContainer()

Prevents optional containers from rendering if they have no children.

Parameters

array $element: An associative array containing the properties and children of the container.

Return value

array The modified element.

File

core/lib/Drupal/Core/Render/Element/Container.php, line 99

Class

Container
Provides a render element that wraps child elements in a container.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderContainer($element) {

  // Do not render optional container elements if there are no children.
  if (empty($element['#printed']) && !empty($element['#optional']) && !Element::getVisibleChildren($element)) {
    $element['#printed'] = TRUE;
  }
  return $element;
}