Change record status: 
Project: 
Introduced in branch: 
11.3.x
Introduced in version: 
11.3.0
Description: 

A majority of plugins implement \Drupal\Component\Plugin\ConfigurableInterface, and each have to provide the getter and setter methods.

Due to the existence of public function defaultConfiguration();, they must also handle merging defaults in with explicit configuration.

To reduce the boilerplate, there is now \Drupal\Core\Plugin\ConfigurablePluginBase class as well as \Drupal\Core\Plugin\ConfigurableTrait.

The trait uses NestedArray::MergeDeepArray to merge the provided configuration with the defaults, which properly merges nested keys while preserving integer keys.

Where possible, a plugin should extend ConfigurablePluginBase to implement ConfigurableInterface. This will properly merge the plugin defaults with the provided configuration in the constructor, and provide the getConfiguration and setConfiguration methods. It will also provide a defaultConfiguration method which returns an empty array. Plugins should override this method with their own defaults.

For plugins that must extend a different plugin base class (and when the base class itself can not extend ConfigurablePluginBase) a trait is also provided to provide the getConfiguration, setConfiguration, and defaultConfiguration methods provided by the interface. If using the trait instead of the base class, it is important to call ->setConfiguration in the class constructor after calling the parent constructor in order to properly merge the provided configuration with the defaults. see https://www.drupal.org/node/2852190 for more detail.

The following plugin base classes have been converted to use the new boilerplate:

ConfigurableActionBase
VariantBase
SelectionPluginBase
LayoutDefault
ImageEffectBase
ConfigurableSearchPluginBase
WorkflowTypeBase

Of those above, All except for ImageEffectBase and WorkflowTypeBase have had their merging logic converted to use mergeDeepArray from either mergeDeep or simple array addition. These should be functionally equivalent, but may return the array keys in a slightly different order, which might require test updates in contrib.

Impacts: 
Module developers