Replace dynamic extension.list.$type service with extension.path.resolver service object

Created on 13 August 2024, 3 months ago

Problem/Motivation

While addressing the PHPCS/PHPStan errors as part of ticket: 📌 Fix validate pipeline Needs review , a PHPStan ignore line was added for the following service call:

\Drupal::service("extension.list.$type")->getPathname($name);

To improve the codebase and adhere to best practices, we should replace this direct service call with the extension.path.resolver service object. This service object accepts extension_type and extension_name as arguments for method getPathName and returns the correct pathname, which aligns with our goal of fixing PHPStan error of avoiding \Drupal::service calls in the classes and increasing code maintainability.

Proposed resolution

  • Modify the config_update.config_list service definition to adds the extension.path.resolver service ias the last argument.
  • Refactor the ConfigLister class constructor to accept the extension.path.resolver service object.
  • Update listProvidedItems method of ConfigLister class and update \Drupal::service("extension.list.$type") service object.
  • Modify the ConfigListerWithProviders class constructor to include the extension.path.resolver service argument.
  • Ensure that the parent constructor is called correctly in ConfigListerWithProviders class if it wasn't already.
  • Review and update any PHPUnit tests that are affected by these changes.
  • Ensure that all tests pass without any PHPStan or PHPCS issues.

Remaining tasks

The ConfigLister class is a base class, and the ConfigListerWithProviders class extends it. Given that other contributed or custom modules might also have extended the ConfigLister class, so we should not make the extension.path.resolver service object a required argument in the ConfigLister class constructor. Instead, we should make it optional for now and include a deprecation notice stating that calling the __construct method of the ConfigLister class without passing the extension.path.resolver

📌 Task
Status

Closed: duplicate

Version

2.0

Component

Base module

Created by

🇮🇳India vishalkhode

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

Comments & Activities

Production build 0.71.5 2024