Loading core/lib/Drupal/Core/Render/Element.php +3 −3 Original line number Diff line number Diff line Loading @@ -187,8 +187,8 @@ public static function setAttributes(array &$element, array $map) { /** * 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. * An element that only has #cache, #weight, or #attached set is considered * empty, because it will render to the empty string. * * @param array $elements * The element. Loading @@ -197,7 +197,7 @@ public static function setAttributes(array &$element, array $map) { * Whether the given element is empty. */ public static function isEmpty(array $elements) { return empty($elements) || (count($elements) === 1 && array_keys($elements) === ['#cache']); return \array_diff(\array_keys($elements), ['#cache', '#weight', '#attached']) === []; } } core/tests/Drupal/Tests/Core/Render/ElementTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,29 @@ public function testIsEmpty(array $element, $expected) { public function providerTestIsEmpty() { return [ [[], TRUE], [['#attached' => []], TRUE], [['#cache' => []], TRUE], [['#weight' => []], TRUE], // Variations. [['#attached' => [], '#cache' => []], TRUE], [['#attached' => [], '#weight' => []], TRUE], [['#attached' => [], '#weight' => [], '#cache' => []], TRUE], [['#cache' => [], '#weight' => []], TRUE], [['#cache' => [], '#weight' => [], '#any_other_property' => []], FALSE], [ [ '#attached' => [], '#weight' => [], '#cache' => [], '#any_other_property' => [], ], FALSE, ], // Cover sorting. [['#cache' => [], '#weight' => [], '#attached' => []], TRUE], [['#attached' => [], '#cache' => [], '#weight' => []], TRUE], [['#weight' => [], '#attached' => [], '#cache' => []], TRUE], [['#cache' => []], TRUE], [['#cache' => ['tags' => ['foo']]], TRUE], [['#cache' => ['contexts' => ['bar']]], TRUE], Loading Loading
core/lib/Drupal/Core/Render/Element.php +3 −3 Original line number Diff line number Diff line Loading @@ -187,8 +187,8 @@ public static function setAttributes(array &$element, array $map) { /** * 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. * An element that only has #cache, #weight, or #attached set is considered * empty, because it will render to the empty string. * * @param array $elements * The element. Loading @@ -197,7 +197,7 @@ public static function setAttributes(array &$element, array $map) { * Whether the given element is empty. */ public static function isEmpty(array $elements) { return empty($elements) || (count($elements) === 1 && array_keys($elements) === ['#cache']); return \array_diff(\array_keys($elements), ['#cache', '#weight', '#attached']) === []; } }
core/tests/Drupal/Tests/Core/Render/ElementTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,29 @@ public function testIsEmpty(array $element, $expected) { public function providerTestIsEmpty() { return [ [[], TRUE], [['#attached' => []], TRUE], [['#cache' => []], TRUE], [['#weight' => []], TRUE], // Variations. [['#attached' => [], '#cache' => []], TRUE], [['#attached' => [], '#weight' => []], TRUE], [['#attached' => [], '#weight' => [], '#cache' => []], TRUE], [['#cache' => [], '#weight' => []], TRUE], [['#cache' => [], '#weight' => [], '#any_other_property' => []], FALSE], [ [ '#attached' => [], '#weight' => [], '#cache' => [], '#any_other_property' => [], ], FALSE, ], // Cover sorting. [['#cache' => [], '#weight' => [], '#attached' => []], TRUE], [['#attached' => [], '#cache' => [], '#weight' => []], TRUE], [['#weight' => [], '#attached' => [], '#cache' => []], TRUE], [['#cache' => []], TRUE], [['#cache' => ['tags' => ['foo']]], TRUE], [['#cache' => ['contexts' => ['bar']]], TRUE], Loading