Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Render/Element/Container.php \Drupal\Core\Render\Element\Container::preRenderContainer()
  2. 9 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

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;
}