Problem/Motivation
ExtraFieldDisplayFormattedBase::view() checks if a field is empty with !empty($elements).
I think it would make more sense to use Element::isEmpty() here, as it would consider a field with only #cache empty.
I know we can manually specify if a field is empty with something like this:
$this->isEmpty = Element::isEmpty($build));
But it would be useful if we did not have to specify it for basic use cases. (Specifying isEmpty manually would still be useful for more complex cases.)
Steps to reproduce
Very basic example of a field that is empty but does not return an empty array:
public function viewElements(ContentEntityInterface $entity): array {
return [
'#cache' => ['max-age' => 42],
];
}
Proposed resolution
We could do something like this:
if (!Element::isEmpty($elements) && !$this->isEmpty()) {
But would this break retro-compatibility? I guess it could consider fields empty that were not considered empty before.
Issue fork extra_field-3443679
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3443679-extra-field
changes, plain diff MR !30
- 3443679-use-elementisempty-to
compare
Comments
Comment #3
pcambraComment #6
pcambraComment #8
pcambraThanks!
Comment #9
pcambra