(PHPStan) Add dependency injection for FieldTargetBase and add deprecation warnings

Created on 13 July 2024, about 2 months ago

Problem/Motivation

In \Drupal\feeds\Plugin\Type\Target\FieldTargetBase, there are three services not injected. These are:

  • \Drupal::entityQuery(), which should be replaced with $this->entityTypeManager->getStorage()->getQuery() and the service 'entity_type.manager' should be injected.
  • \Drupal::service('entity_field.manager'), which should be injected.
  • \Drupal::service('language_manager'), which should be injected.

This will add three parameters to the constructor and because some Feeds plugins that extend FieldTargetBase call its parent constructor, the parameters should become optional.

Proposed resolution

Inject the three serviced mentioned above and add three optional parameters to the constructor. Also in the constructor, trigger an error with a deprecation warning if the three parameters are not set.

Write a change record about this change.

Code example:

if (!isset($entity_type_manager)) {
  @trigger_error('Calling ' . __METHOD__ . '() without the $entity_type_manager argument is deprecated in feeds:3.0.0-rc1 and will be required in feeds:4.0.0. See https://www.drupal.org/node/xxx', E_USER_DEPRECATED);
  $entity_type_manager = \Drupal::service('entity_type.manager');
}

'xxx' should be the node ID of the change record.

Remaining tasks

  • Draft a change record.
  • Add dependency injection for FieldTargetBase with additional constructor parameters being made optional.
  • Trigger an error with a deprecation warning for each newly added optional constructor parameter that is not set.
  • Commit.
  • Publish the change record.

User interface changes

None.

API changes

\Drupal\feeds\Plugin\Type\Target\FieldTargetBase::__construct() will get three optional additional parameters. An error with a deprecation warning is triggered when these are not set.

Data model changes

None.

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands MegaChriz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024