Problem/Motivation

Split from #2015121: Inject various dependencies into DisplayPluginBase. Using a service locator model to inject views plugin managers in the views display plugin classes was proposed in #52 and #59
there. This issue is to introduce the service locator and deprecate the Views::pluginManager() and Views::handerManager() methods.

Steps to reproduce

Proposed resolution

See MR!14258 from #2015121: Inject various dependencies into DisplayPluginBase as reference for implementing the service locator.

The deprecate Views::pluginManager() and Views::handerManager() by replacing the use of Drupal::service() with service locator instead and triggering the appropriate deprecations.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3566424

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

godotislate created an issue. See original summary.

longwave made their first commit to this issue’s fork.

longwave’s picture

Status: Active » Needs review

Unsure if we should trigger deprecations or not yet.

godotislate’s picture

Unsure if we should trigger deprecations or not yet.

A quick search shows 34 uses of pluginManager() and 9 uses of handlerManager() in core. Haven't looked closely, but I'm guessing more than a few uses aren't easily injectable, so maybe we defer deprecation.

longwave’s picture

We could bulk replace existing uses with \Drupal::service('views.plugin_managers') (or the specific manager for static cases), which would start us down that road I suppose.

godotislate’s picture

That sounds good to me.

longwave’s picture

Converted existing uses and added a test.

Disclaimer: parts of this MR were assisted by Claude Code.

godotislate’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record, +Needs followup

This needs a CR for the deprecation, so tagging for that. The MR will need to be updated with the CR URL once avaiable.

Also tagging 'Needs followup' for issue(s) to dependency inject the service locator or specific views plugin managers wherever possible.

MR otherwise looks good.

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Added CR and updated the link: https://www.drupal.org/node/3566982

godotislate’s picture

Status: Needs review » Reviewed & tested by the community

CR and MR lgtm.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and 11.x, thanks!

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.

  • catch committed 0e62d29a on 11.x
    task: #3566424 Deprecate Views::pluginManager() and Views::...

  • catch committed 26a0c062 on main
    task: #3566424 Deprecate Views::pluginManager() and Views::...
mondrake’s picture

This added two instances of #[Group('legacy')] attribute usage in ViewsTest, that are not correct: https://www.drupal.org/node/3447698

The @group legacy annotation, that in old tests was used to indicate to the Symfony PHPUnit-bridge tests that were expected to check deprecations, must be replaced by the #[IgnoreDeprecations] attribute.

Will be fixed in #3497124: Deprecate expectDeprecation(), use PHPUnit's expectUserDeprecationMessage*() instead.

joelpittet’s picture

What's the best way to support D10 onward with this kinda change? Is that something we can add as an addendum to the CR? Edit ignore me...

Sorry, I guess in D10 support I can just go with:

-      $filterHandler = Views::handlerManager('filter');
+      $filterHandler = \Drupal::service('plugin.manager.views.filter');

Was looking at the code and it's just a wrapper.

Status: Fixed » Closed (fixed)

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