Issue #3117291 by NitinLama, smustgrave, silverham, Chi: Element::isEmpty() should check for #weight property
parent
90f0da7baf
commit
c3f6ce5cc0
|
@ -187,8 +187,8 @@ class Element {
|
|||
/**
|
||||
* 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.
|
||||
|
@ -197,7 +197,7 @@ class Element {
|
|||
* 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']) === [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -188,6 +188,29 @@ class ElementTest extends UnitTestCase {
|
|||
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…
Reference in New Issue