Problem/Motivation

I have a QueueWorker class that I'd like to autowire in 11.3.x, but because QueueWorkerBase inherits directly from Drupal\Component\Plugin\PluginBase instead of Drupal\Core\Plugin\PluginBase, it does not use AutowiredInstanceTrait, nor does it have a ready-built create() method.

Steps to reproduce

  1. Create a new class, under modules/contrib/mymodule/src/Plugin/QueueWorker, inheriting from QueueWorkerBase, and implementing ContainerFactoryPluginInterface.
  2. Add a constructor:
      public function __construct(
        array $configuration, $plugin_id, $plugin_definition,
        protected EntityTypeManagerInterface $entityTypeManager,
      ) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
      }
    
  3. Note that you have to write your own create() method. There is no auto-wiring. The best-case scenario is to use AutowiredInstanceTrait and then copy the create method from Drupal\Core\Plugin\PluginBase.

Proposed resolution

Make QueueWorkerBase inherit from Drupal\Core\Plugin\PluginBase instead of Drupal\Component\Plugin\PluginBase

Remaining tasks

N/A

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

TBD

Issue fork drupal-3566682

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

daniel_j created an issue. See original summary.

quietone’s picture

Version: 11.3.x-dev » 11.x-dev

Hi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. The version the problem was discovered should be stated in the issue summary Problem/Motivation section. Thanks.

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.

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

aaronbauman’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

This seems fine because core PluginBase extends use Drupal\Component\Plugin\PluginBase so don't believe anything is lost or this would be disruptive for anyone.

  • amateescu committed 8717214c on 11.x
    task: #3566682 QueueWorkerBase should inherit from Core's PluginBase,...

  • amateescu committed 0f17f619 on main
    task: #3566682 QueueWorkerBase should inherit from Core's PluginBase,...
amateescu’s picture

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

Makes sense to me as well.

Committed and pushed 0f17f619465 to main and 8717214c291 to 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.

Status: Fixed » Closed (fixed)

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