Problem/Motivation
Using phpstan on a project revealed that the signature of \Drupal\Core\Field\FieldItemInterface::view() and \Drupal\Core\Field\FieldItemListInterface::view() are incorrect.
They both have the following phpdoc for the $display_options argument:
* @param array $display_options
* Can be either the name of a view mode, or an array of display settings.
* See EntityViewBuilderInterface::viewField() for more information.
The type should be string|array instead of just array to be consistent with the description and with EntityViewBuilderInterface::viewField().
Proposed resolution
Fix the type hint.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Not needed?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal-incorrect-signature-3173004-2-9.0.x.patch | 1.24 KB | beram |
Comments
Comment #2
beram commentedHere's the patch.
Comment #3
klausiThanks, makes sense and applies cleanly to 9.2.x.
Comment #4
xjmGood catch! Confirmed this is accurate based on the rest of the method docs and at EntityViewBuilder::viewField(). I also checked around other places in the call chain and elsewhere it's properly labeled as
string|array.Comment #9
xjmAs a documentation bugfix, this is eligible for backport during the alpha and to production branches, so committed to 9.2.x with cherry-picks to 9.1.x, 9.0.x, and 8.9.x. Thanks!
Comment #10
xjm