diff --git a/core/lib/Drupal/Core/Action/ConfigurableActionBase.php b/core/lib/Drupal/Core/Action/ConfigurableActionBase.php index 6c19540bd39321808882f197087702eb8bb5c710..2bbc9122c27e3457d6f9a3080ba06352b44bbede 100644 --- a/core/lib/Drupal/Core/Action/ConfigurableActionBase.php +++ b/core/lib/Drupal/Core/Action/ConfigurableActionBase.php @@ -17,7 +17,7 @@ abstract class ConfigurableActionBase extends ActionBase implements Configurable public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->configuration += $this->defaultConfiguration(); + $this->setConfiguration($configuration); } /** @@ -38,7 +38,7 @@ public function getConfiguration() { * {@inheritdoc} */ public function setConfiguration(array $configuration) { - $this->configuration = $configuration; + $this->configuration = $configuration + $this->defaultConfiguration(); } /** diff --git a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php index bbcb0f2a6150ffdeb7a02095fbbe48745d39b56e..e2bff29422aa393db072469f90fd3743fa9be3eb 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php @@ -52,10 +52,7 @@ class DefaultSingleLazyPluginCollection extends LazyPluginCollection { */ public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration) { $this->manager = $manager; - $this->instanceId = $instance_id; - // This is still needed by the parent LazyPluginCollection class. - $this->instanceIDs = array($instance_id => $instance_id); - $this->configuration = $configuration; + $this->addInstanceId($instance_id, $configuration); } /** @@ -95,6 +92,8 @@ public function setConfiguration($configuration) { */ public function addInstanceId($id, $configuration = NULL) { $this->instanceId = $id; + // Reset the list of instance IDs since there can be only one. + $this->instanceIDs = []; parent::addInstanceId($id, $configuration); if ($configuration !== NULL) { $this->setConfiguration($configuration); diff --git a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php index 2e034477878e81e3377636193f037cdd65b8ba7e..6ab2ad9875f28ab6a9dcfc2ec5a6c54b2982f9e8 100644 --- a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php +++ b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php @@ -62,6 +62,9 @@ protected function setUpModerationInformation(ContentEntityInterface $entity) { // mocked. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_manager = $this->prophesize(WorkflowTypeManager::class); diff --git a/core/modules/search/src/Plugin/ConfigurableSearchPluginBase.php b/core/modules/search/src/Plugin/ConfigurableSearchPluginBase.php index 3a39cbc16e95d9041ad65e71a4af311a75fea6df..4f259831d0ce91a84cd1fa69c7447bab8d748f78 100644 --- a/core/modules/search/src/Plugin/ConfigurableSearchPluginBase.php +++ b/core/modules/search/src/Plugin/ConfigurableSearchPluginBase.php @@ -23,7 +23,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $this->configuration); + $this->setConfiguration($configuration); } /** @@ -44,7 +44,7 @@ public function getConfiguration() { * {@inheritdoc} */ public function setConfiguration(array $configuration) { - $this->configuration = $configuration; + $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration); } /** diff --git a/core/modules/workflows/tests/src/Unit/StateTest.php b/core/modules/workflows/tests/src/Unit/StateTest.php index 82feca34627b02c28e3f80e969245347b9b47054..ae9fc462023351b489ced5b0950a9ff11d3124b8 100644 --- a/core/modules/workflows/tests/src/Unit/StateTest.php +++ b/core/modules/workflows/tests/src/Unit/StateTest.php @@ -27,6 +27,9 @@ protected function setUp() { // mocked. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_type->deleteState(Argument::any())->willReturn(NULL); diff --git a/core/modules/workflows/tests/src/Unit/TransitionTest.php b/core/modules/workflows/tests/src/Unit/TransitionTest.php index 3202e8a46644873023dd4c847c87d7955f48e3c4..c343fed9273b83a9accb1dacfc55d48b77450fe7 100644 --- a/core/modules/workflows/tests/src/Unit/TransitionTest.php +++ b/core/modules/workflows/tests/src/Unit/TransitionTest.php @@ -27,6 +27,9 @@ protected function setUp() { // mocked. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_manager = $this->prophesize(WorkflowTypeManager::class); diff --git a/core/modules/workflows/tests/src/Unit/WorkflowTest.php b/core/modules/workflows/tests/src/Unit/WorkflowTest.php index 89ee31f6baae23849e9347d144e3036d8825e7a5..e2a7401cec1166ac271365b96cbbe0d6f6fe4de5 100644 --- a/core/modules/workflows/tests/src/Unit/WorkflowTest.php +++ b/core/modules/workflows/tests/src/Unit/WorkflowTest.php @@ -27,6 +27,9 @@ protected function setUp() { // mocked. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_manager = $this->prophesize(WorkflowTypeManager::class); @@ -215,6 +218,9 @@ public function testDeleteState() { // correctly. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_type->deleteState('draft')->shouldBeCalled(); @@ -636,6 +642,9 @@ public function testDeleteTransition() { // correctly. $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); + $workflow_type->setConfiguration(Argument::any())->will(function ($arguments) { + $this->getConfiguration()->willReturn($arguments[0]); + }); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); $workflow_type->decorateTransition(Argument::any())->willReturnArgument(0); $workflow_type->deleteTransition('publish')->shouldBeCalled(); diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php index 22ecd3c4da50a52214b2e2b7d673dad8b2d9ecda..ab7bfdc1dbf5ece960fefafc2ad731a902651eb1 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php @@ -58,6 +58,17 @@ public function testAddInstanceId() { $this->assertEquals(['id' => 'banana', 'key' => 'other_value'], $this->defaultPluginCollection->get('banana')->getConfiguration()); } + /** + * @covers ::getInstanceIds + */ + public function testGetInstanceIds() { + $this->setupPluginCollection($this->any()); + $this->assertEquals(['apple' => 'apple'], $this->defaultPluginCollection->getInstanceIds()); + + $this->defaultPluginCollection->addInstanceId('banana', ['id' => 'banana', 'key' => 'other_value']); + $this->assertEquals(['banana' => 'banana'], $this->defaultPluginCollection->getInstanceIds()); + } + } class ConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface {