diff --git a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php index 1f5a4c2..01d1b43 100644 --- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Entity\EntityReferenceSelection; use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; @@ -84,9 +85,11 @@ public function setConfiguration(array $configuration) { $handler_settings = !empty($configuration['handler_settings']) ? $configuration['handler_settings'] : []; unset($configuration['handler_settings']); - // Merge in BC layer and defaults. Settings passed in the root level take - // precedence over BC settings. - $this->configuration = $configuration + $handler_settings + $default_config; + // Settings passed in the root level take precedence over BC settings. + $configuration += $handler_settings; + + // Merge in BC layer and defaults. + $this->configuration = NestedArray::mergeDeep($default_config, $configuration); // Synchronize back 'handler_settings'. // @todo Remove this sync in Drupal 9.0.x diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php index de6f665..f041727 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php @@ -61,7 +61,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $configuration = $this->getConfiguration(); - debug($configuration['sort']); $entity_type_id = $configuration['target_type']; $entity_type = $this->entityManager->getDefinition($entity_type_id); $bundles = $this->entityManager->getBundleInfo($entity_type_id); diff --git a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php index 7a17cf7..75fc052 100644 --- a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php +++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php @@ -23,6 +23,18 @@ class TermSelection extends DefaultSelection { /** * {@inheritdoc} */ + public function defaultConfiguration() { + return [ + 'sort' => [ + 'field' => 'name', + 'direction' => 'asc', + ] + ] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); @@ -41,9 +53,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta */ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { if ($match || $limit) { - $configuration = $this->getConfiguration(); - $configuration['sort'] = ['field' => 'name', 'direction' => 'asc']; - $this->setConfiguration($configuration); return parent::getReferenceableEntities($match, $match_operator, $limit); } diff --git a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php index f4ec44e..0ad56b0 100644 --- a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php +++ b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php @@ -37,14 +37,20 @@ public function providerTestSetConfiguration() { [ [ 'setting1' => 'foo', - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'bar' => 'bar value', + 'baz' => 'baz value', + ], ], ], [ [ 'handler_settings' => [ 'setting1' => 'foo', - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'bar' => 'bar value', + 'baz' => 'baz value', + ], ], ], ], @@ -52,14 +58,20 @@ public function providerTestSetConfiguration() { [ 'setting1' => 'foo', 'handler_settings' => [ - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'bar' => 'bar value', + 'baz' => 'baz value', + ], ] ], ], [ [ 'setting1' => 'foo', - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'bar' => 'bar value', + 'baz' => 'baz value', + ], 'handler_settings' => [ // Same setting from root level takes precedence. 'setting2' => 'this will be overwritten', @@ -80,18 +92,25 @@ public function providerTestSetConfiguration() { */ public function testSetConfiguration($options) { $selection = new TestSelection($options, 'test_selector', []); - $selection->setConfiguration($options); $expected = [ 'target_type' => NULL, 'handler' => 'test_selector', 'entity' => NULL, 'setting1' => 'foo', - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'qux' => 'qux value', + 'bar' => 'bar value', + 'baz' => 'baz value', + ], 'setting3' => 'foobar', 'handler_settings' => [ 'setting1' => 'foo', - 'setting2' => ['bar', 'baz'], + 'setting2' => [ + 'qux' => 'qux value', + 'bar' => 'bar value', + 'baz' => 'baz value', + ], 'setting3' => 'foobar', ], ]; @@ -117,11 +136,11 @@ public function testSetConfigurationBcLevel() { 'handler' => 'test_selector', 'entity' => NULL, 'setting1' => 'foo', - 'setting2' => ['qux'], + 'setting2' => ['qux' => 'qux value'], 'setting3' => 'foobar', 'handler_settings' => [ 'setting1' => 'foo', - 'setting2' => ['qux'], + 'setting2' => ['qux' => 'qux value'], 'setting3' => 'foobar', ], ]; @@ -147,7 +166,9 @@ class TestSelection extends SelectionPluginBase { public function defaultConfiguration() { return [ - 'setting2' => ['qux'], + 'setting2' => [ + 'qux' => 'qux value', + ], 'setting3' => 'foobar', ] + parent::defaultConfiguration(); }