From 4bb82a8eb5e6cf2259c15764f7dd8ac05c4c12a4 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sun, 24 Feb 2019 13:42:45 +0000 Subject: [PATCH] Issue #2946122 by mikelutz, heddn, tim.plunkett, phenaproxima, alexpott, joelpittet, MegaChriz, joachim, xjm: Deprecate ConfigurablePluginInterface and replace with an interface that doesn't extend DependentPluginInterface --- core/core.api.php | 3 +- .../Plugin/ConfigurableInterface.php | 36 +++++++++++ .../Plugin/ConfigurablePluginInterface.php | 9 +++ .../Drupal/Component/Plugin/PluginBase.php | 16 ++++- .../Drupal/Component/Plugin/PluginHelper.php | 31 ++++++++++ .../Core/Action/ConfigurableActionBase.php | 4 +- .../Core/Block/BlockPluginInterface.php | 6 +- .../Core/Condition/ConditionInterface.php | 4 +- .../Drupal/Core/Display/VariantInterface.php | 4 +- .../SelectionPluginBase.php | 4 +- .../Core/Field/PluginSettingsInterface.php | 2 +- .../Drupal/Core/Layout/LayoutInterface.php | 6 +- .../Core/Plugin/ContextAwarePluginBase.php | 6 +- .../Plugin/DefaultLazyPluginCollection.php | 6 +- .../DefaultSingleLazyPluginCollection.php | 6 +- .../Plugin/AggregatorPluginSettingsBase.php | 4 +- .../filter/src/Plugin/FilterInterface.php | 6 +- .../image/src/ImageEffectInterface.php | 4 +- .../media/src/MediaSourceInterface.php | 4 +- .../ConfigurableSearchPluginInterface.php | 4 +- core/modules/system/src/Entity/Action.php | 4 +- .../workflows/src/WorkflowTypeInterface.php | 4 +- .../ConfigurablePluginInterfaceTest.php | 59 +++++++++++++++++++ .../Tests/Core/Plugin/ContextHandlerTest.php | 5 +- .../DefaultLazyPluginCollectionTest.php | 34 ++++++++++- .../DefaultSingleLazyPluginCollectionTest.php | 8 +-- .../Fixtures/TestConfigurablePlugin.php | 5 +- 27 files changed, 244 insertions(+), 40 deletions(-) create mode 100644 core/lib/Drupal/Component/Plugin/ConfigurableInterface.php create mode 100644 core/lib/Drupal/Component/Plugin/PluginHelper.php create mode 100644 core/tests/Drupal/Tests/Component/Plugin/ConfigurablePluginInterfaceTest.php diff --git a/core/core.api.php b/core/core.api.php index 0cfea5b8c9c0..00e7e1fcc5b6 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -1382,7 +1382,8 @@ * instantiated. Usually this interface will extend one or more of the * following interfaces: * - \Drupal\Component\Plugin\PluginInspectionInterface - * - \Drupal\Component\Plugin\ConfigurablePluginInterface + * - \Drupal\Component\Plugin\ConfigurableInterface + * - \Drupal\Component\Plugin\DependentPluginInterface * - \Drupal\Component\Plugin\ContextAwarePluginInterface * - \Drupal\Core\Plugin\PluginFormInterface * - \Drupal\Core\Executable\ExecutableInterface diff --git a/core/lib/Drupal/Component/Plugin/ConfigurableInterface.php b/core/lib/Drupal/Component/Plugin/ConfigurableInterface.php new file mode 100644 index 000000000000..5de59d1ba818 --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/ConfigurableInterface.php @@ -0,0 +1,36 @@ +<?php + +namespace Drupal\Component\Plugin; + +/** + * Provides an interface for a configurable plugin. + * + * @ingroup plugin_api + */ +interface ConfigurableInterface { + + /** + * Gets this plugin's configuration. + * + * @return array + * An array of this plugin's configuration. + */ + public function getConfiguration(); + + /** + * Sets the configuration for this plugin instance. + * + * @param array $configuration + * An associative array containing the plugin's configuration. + */ + public function setConfiguration(array $configuration); + + /** + * Gets default configuration for this plugin. + * + * @return array + * An associative array with the default configuration. + */ + public function defaultConfiguration(); + +} diff --git a/core/lib/Drupal/Component/Plugin/ConfigurablePluginInterface.php b/core/lib/Drupal/Component/Plugin/ConfigurablePluginInterface.php index 90bab254a05c..1fa69b893120 100644 --- a/core/lib/Drupal/Component/Plugin/ConfigurablePluginInterface.php +++ b/core/lib/Drupal/Component/Plugin/ConfigurablePluginInterface.php @@ -5,6 +5,15 @@ /** * Provides an interface for a configurable plugin. * + * @deprecated Drupal\Component\Plugin\ConfigurablePluginInterface is deprecated + * in Drupal 8.7.0 and will be removed before Drupal 9.0.0. You should implement + * ConfigurableInterface and/or DependentPluginInterface directly as needed. If + * you implement ConfigurableInterface you may choose to implement + * ConfigurablePluginInterface in Drupal 8 as well for maximum compatibility, + * however this must be removed prior to Drupal 9. + * + * @see https://www.drupal.org/node/2946161 + * * @ingroup plugin_api */ interface ConfigurablePluginInterface extends DependentPluginInterface { diff --git a/core/lib/Drupal/Component/Plugin/PluginBase.php b/core/lib/Drupal/Component/Plugin/PluginBase.php index c56442b1ecf9..e7e980ade48f 100644 --- a/core/lib/Drupal/Component/Plugin/PluginBase.php +++ b/core/lib/Drupal/Component/Plugin/PluginBase.php @@ -30,7 +30,7 @@ abstract class PluginBase implements PluginInspectionInterface, DerivativeInspec * Configuration information passed into the plugin. * * When using an interface like - * \Drupal\Component\Plugin\ConfigurablePluginInterface, this is where the + * \Drupal\Component\Plugin\ConfigurableInterface, this is where the * configuration should be stored. * * Plugin configuration is optional, so plugin implementations must provide @@ -54,6 +54,10 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->configuration = $configuration; $this->pluginId = $plugin_id; $this->pluginDefinition = $plugin_definition; + + if ($this instanceof ConfigurablePluginInterface && !$this instanceof ConfigurableInterface) { + @trigger_error('Drupal\Component\Plugin\ConfigurablePluginInterface is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. You should implement ConfigurableInterface and/or DependentPluginInterface directly as needed. If you implement ConfigurableInterface you may choose to implement ConfigurablePluginInterface in Drupal 8 as well for maximum compatibility, however this must be removed prior to Drupal 9. See https://www.drupal.org/node/2946161', E_USER_DEPRECATED); + } } /** @@ -93,4 +97,14 @@ public function getPluginDefinition() { return $this->pluginDefinition; } + /** + * Determines if the plugin is configurable. + * + * @return bool + * A boolean indicating whether the plugin is configurable. + */ + public function isConfigurable() { + return $this instanceof ConfigurableInterface || $this instanceof ConfigurablePluginInterface; + } + } diff --git a/core/lib/Drupal/Component/Plugin/PluginHelper.php b/core/lib/Drupal/Component/Plugin/PluginHelper.php new file mode 100644 index 000000000000..fe1023bdced4 --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/PluginHelper.php @@ -0,0 +1,31 @@ +<?php + +namespace Drupal\Component\Plugin; + +/** + * A helper class to determine if a plugin is configurable. + * + * Because configurable plugins in Drupal 8 might implement either the + * deprecated ConfigurablePluginInterface or the new ConfigurableInterface, + * this static method is provided so that a calling class can determine if a + * plugin is configurable without checking it against a deprecated interface. + * In Drupal 9, this check should be reduced to checking for + * ConfigurableInterface only and be deprecated in favor of calling classes + * checking against the interface directly. + */ +class PluginHelper { + + /** + * Determines if a plugin is configurable. + * + * @param mixed $plugin + * The plugin to check. + * + * @return bool + * A boolean indicating whether the plugin is configurable. + */ + public static function isConfigurable($plugin) { + return $plugin instanceof ConfigurableInterface || $plugin instanceof ConfigurablePluginInterface; + } + +} diff --git a/core/lib/Drupal/Core/Action/ConfigurableActionBase.php b/core/lib/Drupal/Core/Action/ConfigurableActionBase.php index 3d372fe64695..49c40800c28a 100644 --- a/core/lib/Drupal/Core/Action/ConfigurableActionBase.php +++ b/core/lib/Drupal/Core/Action/ConfigurableActionBase.php @@ -2,14 +2,16 @@ namespace Drupal\Core\Action; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; /** * Provides a base implementation for a configurable Action plugin. */ -abstract class ConfigurableActionBase extends ActionBase implements ConfigurablePluginInterface, PluginFormInterface { +abstract class ConfigurableActionBase extends ActionBase implements ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginFormInterface { /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Block/BlockPluginInterface.php b/core/lib/Drupal/Core/Block/BlockPluginInterface.php index b3cf88e0b89f..b7511a5c37eb 100644 --- a/core/lib/Drupal/Core/Block/BlockPluginInterface.php +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php @@ -2,10 +2,12 @@ namespace Drupal\Core\Block; +use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Session\AccountInterface; @@ -20,7 +22,7 @@ * * @ingroup block_api */ -interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface, CacheableDependencyInterface, DerivativeInspectionInterface { +interface BlockPluginInterface extends ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface, CacheableDependencyInterface, DerivativeInspectionInterface { /** * Indicates the block label (title) should be displayed to end users. diff --git a/core/lib/Drupal/Core/Condition/ConditionInterface.php b/core/lib/Drupal/Core/Condition/ConditionInterface.php index 40bdf6078a13..2d35c491c89f 100644 --- a/core/lib/Drupal/Core/Condition/ConditionInterface.php +++ b/core/lib/Drupal/Core/Condition/ConditionInterface.php @@ -2,7 +2,9 @@ namespace Drupal\Core\Condition; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Executable\ExecutableInterface; @@ -42,7 +44,7 @@ * * @ingroup plugin_api */ -interface ConditionInterface extends ExecutableInterface, PluginFormInterface, ConfigurablePluginInterface, PluginInspectionInterface, CacheableDependencyInterface { +interface ConditionInterface extends ExecutableInterface, PluginFormInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginInspectionInterface, CacheableDependencyInterface { /** * Determines whether condition result will be negated. diff --git a/core/lib/Drupal/Core/Display/VariantInterface.php b/core/lib/Drupal/Core/Display/VariantInterface.php index 20a77f16d23e..41dc0a5e1da7 100644 --- a/core/lib/Drupal/Core/Display/VariantInterface.php +++ b/core/lib/Drupal/Core/Display/VariantInterface.php @@ -2,7 +2,9 @@ namespace Drupal\Core\Display; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -16,7 +18,7 @@ * @see \Drupal\Core\Display\VariantManager * @see plugin_api */ -interface VariantInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface, RefinableCacheableDependencyInterface { +interface VariantInterface extends PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginFormInterface, RefinableCacheableDependencyInterface { /** * Returns the user-facing display variant label. diff --git a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php index 1e48a3e052af..598bbcecfa5d 100644 --- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php @@ -2,7 +2,9 @@ namespace Drupal\Core\Entity\EntityReferenceSelection; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Form\FormStateInterface; @@ -11,7 +13,7 @@ /** * Provides a base class for configurable selection handlers. */ -abstract class SelectionPluginBase extends PluginBase implements SelectionInterface, ConfigurablePluginInterface { +abstract class SelectionPluginBase extends PluginBase implements SelectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface { /** * Constructs a new selection object. diff --git a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php index 592ca15d25f2..61ca95d92eaf 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php @@ -9,7 +9,7 @@ * Interface definition for plugin with settings. * * @deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. Use - * \Drupal\Component\Plugin\ConfigurablePluginInterface instead. + * \Drupal\Component\Plugin\ConfigurableInterface instead. */ interface PluginSettingsInterface extends PluginInspectionInterface, ThirdPartySettingsInterface { diff --git a/core/lib/Drupal/Core/Layout/LayoutInterface.php b/core/lib/Drupal/Core/Layout/LayoutInterface.php index 32ee74d18b04..75b8348ccc8b 100644 --- a/core/lib/Drupal/Core/Layout/LayoutInterface.php +++ b/core/lib/Drupal/Core/Layout/LayoutInterface.php @@ -2,14 +2,16 @@ namespace Drupal\Core\Layout; +use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; /** * Provides an interface for static Layout plugins. */ -interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurablePluginInterface { +interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface { /** * Build a render array for layout with regions. diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index ed8abf17fad0..c40c02783f58 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -2,9 +2,9 @@ namespace Drupal\Core\Plugin; -use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\ContextAwarePluginBase as ComponentContextAwarePluginBase; use Drupal\Component\Plugin\Exception\ContextException; +use Drupal\Component\Plugin\PluginHelper; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -78,7 +78,7 @@ public function setContextValue($name, $value) { * {@inheritdoc} */ public function getContextMapping() { - $configuration = $this instanceof ConfigurablePluginInterface ? $this->getConfiguration() : $this->configuration; + $configuration = PluginHelper::isConfigurable($this) ? $this->getConfiguration() : $this->configuration; return isset($configuration['context_mapping']) ? $configuration['context_mapping'] : []; } @@ -86,7 +86,7 @@ public function getContextMapping() { * {@inheritdoc} */ public function setContextMapping(array $context_mapping) { - if ($this instanceof ConfigurablePluginInterface) { + if (PluginHelper::isConfigurable($this)) { $configuration = $this->getConfiguration(); $configuration['context_mapping'] = array_filter($context_mapping); $this->setConfiguration($configuration); diff --git a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php index 3c48892ad5ce..8af3b2f12459 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php @@ -4,8 +4,8 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Plugin\LazyPluginCollection; +use Drupal\Component\Plugin\PluginHelper; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; /** @@ -112,7 +112,7 @@ public function getConfiguration() { $this->instanceIDs = $this->originalOrder + $current_order; foreach ($this as $instance_id => $instance) { - if ($instance instanceof ConfigurablePluginInterface) { + if (PluginHelper::isConfigurable($instance)) { $instances[$instance_id] = $instance->getConfiguration(); } else { @@ -158,7 +158,7 @@ public function setConfiguration($configuration) { public function setInstanceConfiguration($instance_id, array $configuration) { $this->configurations[$instance_id] = $configuration; $instance = $this->get($instance_id); - if ($instance instanceof ConfigurablePluginInterface) { + if (PluginHelper::isConfigurable($instance)) { $instance->setConfiguration($configuration); } } diff --git a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php index e2bff29422aa..0bc119818ead 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php @@ -2,9 +2,9 @@ namespace Drupal\Core\Plugin; +use Drupal\Component\Plugin\PluginHelper; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\LazyPluginCollection; -use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; /** @@ -67,7 +67,7 @@ protected function initializePlugin($instance_id) { */ public function getConfiguration() { $plugin = $this->get($this->instanceId); - if ($plugin instanceof ConfigurablePluginInterface) { + if (PluginHelper::isConfigurable($plugin)) { return $plugin->getConfiguration(); } else { @@ -81,7 +81,7 @@ public function getConfiguration() { public function setConfiguration($configuration) { $this->configuration = $configuration; $plugin = $this->get($this->instanceId); - if ($plugin instanceof ConfigurablePluginInterface) { + if (PluginHelper::isConfigurable($plugin)) { $plugin->setConfiguration($configuration); } return $this; diff --git a/core/modules/aggregator/src/Plugin/AggregatorPluginSettingsBase.php b/core/modules/aggregator/src/Plugin/AggregatorPluginSettingsBase.php index 403e6a34900a..f5a6fd5b0f29 100644 --- a/core/modules/aggregator/src/Plugin/AggregatorPluginSettingsBase.php +++ b/core/modules/aggregator/src/Plugin/AggregatorPluginSettingsBase.php @@ -2,7 +2,9 @@ namespace Drupal\aggregator\Plugin; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginFormInterface; @@ -19,7 +21,7 @@ * @see \Drupal\aggregator\Plugin\ParserInterface * @see plugin_api */ -abstract class AggregatorPluginSettingsBase extends PluginBase implements PluginFormInterface, ConfigurablePluginInterface { +abstract class AggregatorPluginSettingsBase extends PluginBase implements PluginFormInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface { /** * {@inheritdoc} diff --git a/core/modules/filter/src/Plugin/FilterInterface.php b/core/modules/filter/src/Plugin/FilterInterface.php index cdbe276a50c2..39f9749b04d3 100644 --- a/core/modules/filter/src/Plugin/FilterInterface.php +++ b/core/modules/filter/src/Plugin/FilterInterface.php @@ -2,8 +2,10 @@ namespace Drupal\filter\Plugin; -use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\PluginInspectionInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Form\FormStateInterface; /** @@ -75,7 +77,7 @@ * @see \Drupal\filter\Plugin\FilterBase * @see plugin_api */ -interface FilterInterface extends ConfigurablePluginInterface, PluginInspectionInterface { +interface FilterInterface extends ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginInspectionInterface { /** * Non-HTML markup language filters that generate HTML. diff --git a/core/modules/image/src/ImageEffectInterface.php b/core/modules/image/src/ImageEffectInterface.php index 7174ae585017..4d396fc2c9ca 100644 --- a/core/modules/image/src/ImageEffectInterface.php +++ b/core/modules/image/src/ImageEffectInterface.php @@ -2,7 +2,9 @@ namespace Drupal\image; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Image\ImageInterface; @@ -16,7 +18,7 @@ * @see \Drupal\image\ImageEffectManager * @see plugin_api */ -interface ImageEffectInterface extends PluginInspectionInterface, ConfigurablePluginInterface { +interface ImageEffectInterface extends PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface { /** * Applies an image effect to the image object. diff --git a/core/modules/media/src/MediaSourceInterface.php b/core/modules/media/src/MediaSourceInterface.php index 6d08c2039585..a2dea535a775 100644 --- a/core/modules/media/src/MediaSourceInterface.php +++ b/core/modules/media/src/MediaSourceInterface.php @@ -2,7 +2,9 @@ namespace Drupal\media; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; @@ -66,7 +68,7 @@ * @see \Drupal\media\MediaSourceFieldConstraintsInterface * @see plugin_api */ -interface MediaSourceInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface { +interface MediaSourceInterface extends PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginFormInterface { /** * Default empty value for metadata fields. diff --git a/core/modules/search/src/Plugin/ConfigurableSearchPluginInterface.php b/core/modules/search/src/Plugin/ConfigurableSearchPluginInterface.php index 6bbeecd66d3f..a1d1df229198 100644 --- a/core/modules/search/src/Plugin/ConfigurableSearchPluginInterface.php +++ b/core/modules/search/src/Plugin/ConfigurableSearchPluginInterface.php @@ -2,13 +2,15 @@ namespace Drupal\search\Plugin; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Plugin\PluginFormInterface; /** * Provides an interface for a configurable Search plugin. */ -interface ConfigurableSearchPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, SearchInterface { +interface ConfigurableSearchPluginInterface extends ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface, PluginFormInterface, SearchInterface { /** * Sets the ID for the search page using this plugin. diff --git a/core/modules/system/src/Entity/Action.php b/core/modules/system/src/Entity/Action.php index 964a64e97e84..26c9c39bd3db 100644 --- a/core/modules/system/src/Entity/Action.php +++ b/core/modules/system/src/Entity/Action.php @@ -2,12 +2,12 @@ namespace Drupal\system\Entity; +use Drupal\Component\Plugin\PluginHelper; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\system\ActionConfigEntityInterface; use Drupal\Core\Action\ActionPluginCollection; -use Drupal\Component\Plugin\ConfigurablePluginInterface; /** * Defines the configured action entity. @@ -133,7 +133,7 @@ public function execute(array $entities) { * {@inheritdoc} */ public function isConfigurable() { - return $this->getPlugin() instanceof ConfigurablePluginInterface; + return PluginHelper::isConfigurable($this->getPlugin()); } /** diff --git a/core/modules/workflows/src/WorkflowTypeInterface.php b/core/modules/workflows/src/WorkflowTypeInterface.php index 0cb47a49044a..e07d65d0f65d 100644 --- a/core/modules/workflows/src/WorkflowTypeInterface.php +++ b/core/modules/workflows/src/WorkflowTypeInterface.php @@ -2,14 +2,16 @@ namespace Drupal\workflows; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Core\Plugin\PluginWithFormsInterface; /** * An interface for Workflow type plugins. */ -interface WorkflowTypeInterface extends PluginWithFormsInterface, DerivativeInspectionInterface, ConfigurablePluginInterface { +interface WorkflowTypeInterface extends PluginWithFormsInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface { /** * The key of the global workflow plugin form. diff --git a/core/tests/Drupal/Tests/Component/Plugin/ConfigurablePluginInterfaceTest.php b/core/tests/Drupal/Tests/Component/Plugin/ConfigurablePluginInterfaceTest.php new file mode 100644 index 000000000000..1cf781933ace --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Plugin/ConfigurablePluginInterfaceTest.php @@ -0,0 +1,59 @@ +<?php + +namespace Drupal\Tests\Component\Plugin; + +use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\PluginBase; +use PHPUnit\Framework\TestCase; + +/** + * Tests ConfigurablePluginInterface deprecation. + * + * @group legacy + * @group plugin + */ +class ConfigurablePluginInterfaceTest extends TestCase { + + /** + * Tests the deprecation error is thrown. + * + * @expectedDeprecation Drupal\Component\Plugin\ConfigurablePluginInterface is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. You should implement ConfigurableInterface and/or DependentPluginInterface directly as needed. If you implement ConfigurableInterface you may choose to implement ConfigurablePluginInterface in Drupal 8 as well for maximum compatibility, however this must be removed prior to Drupal 9. See https://www.drupal.org/node/2946161 + */ + public function testDeprecation() { + new ConfigurablePluginInterfaceTestClass([], '', []); + } + +} + +/** + * Test Class to trigger deprecation error. + */ +class ConfigurablePluginInterfaceTestClass extends PluginBase implements ConfigurablePluginInterface { + + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return []; + } + + /** + * {@inheritdoc} + */ + public function setConfiguration(array $configuration) {} + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return []; + } + + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + return []; + } + +} diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 6b6baa477722..3cf6a1d45d34 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -7,7 +7,8 @@ namespace Drupal\Tests\Core\Plugin; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface; use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionTrait; use Drupal\Component\Plugin\Definition\PluginDefinition; @@ -554,7 +555,7 @@ public function testApplyContextMappingConfigurableAssignedMiss() { } -interface TestConfigurableContextAwarePluginInterface extends ContextAwarePluginInterface, ConfigurablePluginInterface { +interface TestConfigurableContextAwarePluginInterface extends ContextAwarePluginInterface, ConfigurableInterface, DependentPluginInterface { } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php index 01b7cd1ccef4..7cc4db008e3e 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -2,7 +2,11 @@ namespace Drupal\Tests\Core\Plugin; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\Component\Plugin\PluginInspectionInterface; +use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\Plugin\DefaultLazyPluginCollection; use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin; /** @@ -14,7 +18,7 @@ class DefaultLazyPluginCollectionTest extends LazyPluginCollectionTestBase { /** * Stores all setup plugin instances. * - * @var \Drupal\Component\Plugin\ConfigurablePluginInterface[] + * @var \Drupal\Component\Plugin\ConfigurableInterface[] */ protected $pluginInstances; @@ -234,4 +238,32 @@ public function testConfigurableSetConfiguration() { } + /** + * Tests that plugin methods are correctly attached to interfaces. + * + * @covers ::getConfiguration + */ + public function testConfigurableInterface() { + $configurable_plugin = $this->prophesize(ConfigurableInterface::class); + $configurable_config = ['id' => 'configurable', 'foo' => 'bar']; + $configurable_plugin->getConfiguration()->willReturn($configurable_config); + + $nonconfigurable_plugin = $this->prophesize(PluginInspectionInterface::class); + $nonconfigurable_config = ['id' => 'non-configurable', 'baz' => 'qux']; + $nonconfigurable_plugin->configuration = $nonconfigurable_config; + + $configurations = [ + 'configurable' => $configurable_config, + 'non-configurable' => $nonconfigurable_config, + ]; + + $plugin_manager = $this->prophesize(PluginManagerInterface::class); + $plugin_manager->createInstance('configurable', $configurable_config)->willReturn($configurable_plugin->reveal()); + $plugin_manager->createInstance('non-configurable', $nonconfigurable_config)->willReturn($nonconfigurable_plugin->reveal()); + + $collection = new DefaultLazyPluginCollection($plugin_manager->reveal(), $configurations); + $this->assertSame($configurations, $collection->getConfiguration()); + + } + } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php index 21bbde83d8ae..cd8b384614b5 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\Plugin; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; @@ -71,7 +71,7 @@ public function testGetInstanceIds() { } -class ConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface { +class ConfigurablePlugin extends PluginBase implements ConfigurableInterface { public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -91,8 +91,4 @@ public function setConfiguration(array $configuration) { $this->configuration = $configuration; } - public function calculateDependencies() { - return []; - } - } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php b/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php index 383b4d2bbff7..e31fba7b59df 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php @@ -2,10 +2,11 @@ namespace Drupal\Tests\Core\Plugin\Fixtures; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginBase; -class TestConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface { +class TestConfigurablePlugin extends PluginBase implements ConfigurableInterface, DependentPluginInterface { /** * {@inheritdoc} -- GitLab