function Element::isEmpty

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element.php \Drupal\Core\Render\Element::isEmpty()
  2. 10 core/lib/Drupal/Core/Render/Element.php \Drupal\Core\Render\Element::isEmpty()
  3. 11.x core/lib/Drupal/Core/Render/Element.php \Drupal\Core\Render\Element::isEmpty()

Indicates whether the given element is empty.

An element that only has #cache set is considered empty, because it will render to the empty string.

Parameters

array $elements: The element.

Return value

bool Whether the given element is empty.

7 calls to Element::isEmpty()
BlockComponentRenderArray::onBuildRender in core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php
Builds render arrays for block plugins and sets it on the event.
BlockViewBuilder::preRender in core/modules/block/src/BlockViewBuilder.php
#pre_render callback for building a block.
ElementTest::testIsEmpty in core/tests/Drupal/Tests/Core/Render/ElementTest.php
@covers ::isEmpty
EntityViewDisplay::buildMultiple in core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php
Builds a renderable array for the components of a set of entities.
LayoutBuilderEntityViewDisplay::buildMultiple in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Builds a renderable array for the components of a set of entities.

... See full list

File

core/lib/Drupal/Core/Render/Element.php, line 198

Class

Element
Provides helper methods for Drupal render elements.

Namespace

Drupal\Core\Render

Code

public static function isEmpty(array $elements) {
    return empty($elements) || count($elements) === 1 && array_keys($elements) === [
        '#cache',
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.