Problem/Motivation

PHPStan reports calls like FieldConfig::loadByName(...)->setTranslatable(TRUE) as a call to an undefined method. There are 49 of these in the baseline, for setTranslatable(), setSetting(), setRequired(), setDefaultValue(), setSettings() and addPropertyConstraints().

This is because FieldConfig::loadByName() and MediaSourceInterface::createSourceField() are documented to return \Drupal\field\FieldConfigInterface, and there are two interfaces called FieldConfigInterface:

  • \Drupal\Core\Field\FieldConfigInterface extends FieldDefinitionInterface and ConfigEntityInterface and declares the setters.
  • \Drupal\field\FieldConfigInterface extends the same interfaces directly, so it has none of those setters.

The concrete class, \Drupal\field\Entity\FieldConfig, already implements the core interface via \Drupal\Core\Field\FieldConfigBase, so the interface hierarchy just doesn't match the class hierarchy.

Steps to reproduce

grep 'Drupal\\\\field\\\\FieldConfigInterface::' core/.phpstan-baseline.php

Proposed resolution

Make the field interface extend the Core\Field interface.

Remaining tasks

Determine why we have two interfaces with the same name and if we still need them both.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

mstrelan created an issue. See original summary.

shank115’s picture

This looks like it might be a duplicate of #2818877 which proposes the same change(making \Drupal\field\FieldConfigInterface extend \Drupal\Core\Field\FieldConfigInterface)

mstrelan’s picture

Status: Active » Closed (duplicate)

Yep sorry about that

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.