Problem/Motivation

As a result of the change of the minimum supported core version to 10.3 in parent issue #3565209: [Meta] Drop support for Drupal 10.2 and below, we should now be able to implement autowiring for services and controllers, as suggested in change records:

Steps to reproduce

Proposed resolution

Impacted files:

  • services yaml files: Add autowire: true and remove arguments:
    admin_toolbar_search.services.yml and admin_toolbar_tools.services.yml.
  • Services and Controller class files: Add use AutowireTrait and update constructors to autowire services:
    AdminToolbarSearchController, AdminToolbarToolsHelper.

Remaining tasks

User interface changes

API changes

Data model changes

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

dydave created an issue. See original summary.

dydave’s picture

Status: Active » Needs review

Quick follow-up on this issue:

All the changes detailed in the issue summary have been implemented and described in the merge request MR !203 above at #2.

Since all the tests and jobs still seem to be passing 🟢, moving issue to Needs review as an attempt to get more testing feedback and reviews.

These changes require Drupal core 10.2 or higher and should probably be merged after related:
#3569351: Drop support for Drupal 10.2 and below

Feel free to let us know if you have any comments, questions or concerns on any aspects of this issue or the suggested changes in the merge request, we would surely be glad to help.
Thanks in advance!

  • dydave committed 783a6e95 on 3.x
    Issue #3570710 by dydave: Used autowiring for the services and...
dydave’s picture

Status: Needs review » Fixed

Merged, thanks!

The merge request switches the services and the search controller to autowiring:

  • admin_toolbar_tools.helper and admin_toolbar_tools.menu_link_rebuild_manager now use _defaults with autowire and autoconfigure, the explicit arguments were removed. The needs_destruction tag of the menu link rebuild manager is kept, since core does not autoconfigure it for DestructableInterface and destruct() must still run without a response (e.g. Drush).
  • admin_toolbar_search.search_links (SearchLinks) is autowired, the cache.toolbar bin and the event_dispatcher service of MenuLinkRebuildManager are named with #[Autowire], since the class alias of the Symfony EventDispatcherInterface is missing on several cores.
  • AdminToolbarSearchController uses AutowireTrait and a constructor instead of create().
  • Added Kernel tests for the autowired services and controllers of both modules (AdminToolbarToolsAutowiringTest, AdminToolbarSearchAutowiringTest), including the destructable service registration and the ToolbarController creation without Views.
  • Moved the chevron, expand and collapse icons to images/ and updated the CSS URLs accordingly, and fixed a library comment and a docblock typo.

ToolbarController is intentionally left with its create() method: it depends on optional services (cache.memory only exists in core 11.3 and above, Views may not be installed) and before core 10.5 and 11.2 AutowireTrait::create() throws an exception on missing services, even for nullable arguments. A comment was added in the code to document this, until these core versions are no longer supported.

Tested with 10.3.x, 10.6.x, 11.3.x, 11.4.x and 11.5.x: all tests pass🟢.

Follow-up: the forms, the menu link plugins and ExtraLinks still use create() and could be converted in a separate issue.

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.

Status: Fixed » Closed (fixed)

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