Create a trait and base class to implement \Drupal\Component\Plugin\ConfigurableInterface

Created on 14 February 2017, over 7 years ago
Updated 15 April 2023, about 1 year ago

Problem/Motivation

#2851635: DefaultSingleLazyPluginCollection retains stale instance IDs shows that base plugin classes should all merge default configuration in the same way. We should make it easy to implement \Drupal\Component\Plugin\ConfigurableInterface.

Proposed resolution

Add new trait and base class and use it where appropriate in core.

Additionally, since the use of this interface requires some work to be done in the constructor, add a base class which does that work in the constructor. Not all plugins will be able to use the base class, as they may need to extend a different class, but it will be useful for those that can. Those that can cannot use the base class can use the trait and reimplement the constructor logic in their own constructor.

Specifically:

Add

  • Drupal\Component\Plugin\ConfigurableTrait
  • Drupal\Core\Plugin\ConfigurablePluginBase

Use the new base class in the following classes:

  • Drupal\Core\Display\VariantBase
  • Drupal\Core\Layout\LayoutDefault
  • Drupal\image\src\ImageEffectBase
  • Drupal\workflows\src\Plugin\WorkflowTypeBase

Use the new trait in the following classes:

  • Drupal\Core\Action\ConfigurableActionBase
  • Drupal\Core\Condition\ConditionPluginBase
  • Drupal\search\src\Plugin\ConfigurableSearchPluginBase

Adjust related tests as needed, and add Drupal/Tests/Component/Plugin/ConfigurableTraitTest.

Remaining tasks

  1. Mention the interface instead of the trait in ConfigurablePluginBase.
  2. In ConfigurableTrait, document that the $configuration property is also defined \Drupal\Component\Plugin\PluginBase.
  3. Decide on if ConfigurableTraitTest needs adjustments.
  4. Make sure that the changes in base classes for certain plugin types are mentioned in the release notes.
  5. (optional) Check if setConfiguration() still needs to be overridden in WorkflowTypeBase.
  6. Rebase the merge request.

User interface changes

None

API changes

New trait

Data model changes

None

Release notes snippet

TODO

📌 Task
Status

Needs work

Version

10.1

Component
Plugin 

Last updated about 18 hours ago

Created by

🇬🇧United Kingdom alexpott 🇪🇺🌍

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024