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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

beram created an issue. See original summary.

beram’s picture

Status: Active » Needs review
FileSize
1.24 KB

Here's the patch.

klausi’s picture

Version: 9.0.x-dev » 9.2.x-dev
Status: Needs review » Reviewed & tested by the community
Issue tags: +PHPStan

Thanks, makes sense and applies cleanly to 9.2.x.

xjm’s picture

Title: Incorrect signature for FieldItemInterface::view() and FieldItemListInterface::view(): $display_options could also be a string » Incorrect typehint documentation for FieldItemInterface::view() and FieldItemListInterface::view(): $display_options could also be a string

Good 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.

  • xjm committed 6a910ad on 9.2.x
    Issue #3173004 by beram: Incorrect typehint documentation for...

  • xjm committed d81b187 on 9.1.x
    Issue #3173004 by beram: Incorrect typehint documentation for...

  • xjm committed 6abcb74 on 9.0.x
    Issue #3173004 by beram: Incorrect typehint documentation for...

  • xjm committed 068fd0b on 8.9.x
    Issue #3173004 by beram: Incorrect typehint documentation for...
xjm’s picture

Version: 9.2.x-dev » 8.9.x-dev

As 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!

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.