Verified Commit 871bc1ac authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3404023 by Wim Leers, phenaproxima, mglaman, borisson_, alexpott:...

Issue #3404023 by Wim Leers, phenaproxima, mglaman, borisson_, alexpott: DefaultSingleLazyPluginCollection::setConfiguration() accepts NULL but ConfigurableInterface::setConfiguration() does not
parent 31a6cdf3
Loading
Loading
Loading
Loading
Loading
+5
Changes for core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -128,6 +128,11 @@ public function getConfiguration() {
   * {@inheritdoc}
   */
  public function setConfiguration($configuration) {
    if (!is_array($configuration)) {
      @trigger_error('Calling ' . __METHOD__ . '() with a non-array argument is deprecated in drupal:10.3.0 and will fail in drupal:11.0.0. See https://www.drupal.org/node/3406191', E_USER_DEPRECATED);
      $configuration = [];
    }

    // Track each instance ID as it is updated.
    $unprocessed_instance_ids = $this->getInstanceIds();

+5
Changes for core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -79,6 +79,11 @@ public function getConfiguration() {
   * {@inheritdoc}
   */
  public function setConfiguration($configuration) {
    if (!is_array($configuration)) {
      @trigger_error('Calling ' . __METHOD__ . '() with a non-array argument is deprecated in drupal:10.3.0 and will fail in drupal:11.0.0. See https://www.drupal.org/node/3406191', E_USER_DEPRECATED);
      $configuration = [];
    }

    $this->configuration = $configuration;
    $plugin = $this->get($this->instanceId);
    if ($plugin instanceof ConfigurableInterface) {
+14
Changes for core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -232,11 +232,25 @@ public function testConfigurableSetConfiguration() {
    $plugin = $this->pluginInstances['apple'];
    $this->assertSame(['value' => 'pineapple', 'id' => 'apple'], $plugin->getConfiguration());

    $this->defaultPluginCollection->setConfiguration([]);
    $this->assertSame([], $this->defaultPluginCollection->getConfiguration());

    $this->defaultPluginCollection->setConfiguration(['cherry' => ['value' => 'kiwi', 'id' => 'cherry']]);
    $expected['cherry'] = ['value' => 'kiwi', 'id' => 'cherry'];
    $config = $this->defaultPluginCollection->getConfiguration();
    $this->assertSame($expected, $config);
  }

  /**
   * @covers ::setConfiguration
   * @group legacy
   */
  public function testConfigurableSetConfigurationToNull(): void {
    $this->setupPluginCollection($this->any());

    $this->expectDeprecation('Calling Drupal\Core\Plugin\DefaultLazyPluginCollection::setConfiguration() with a non-array argument is deprecated in drupal:10.3.0 and will fail in drupal:11.0.0. See https://www.drupal.org/node/3406191');
    $this->defaultPluginCollection->setConfiguration(NULL);
    $this->assertSame([], $this->defaultPluginCollection->getConfiguration());
  }

  /**
+33
Changes for core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -70,6 +70,39 @@ public function testGetInstanceIds() {
    $this->assertEquals(['banana' => 'banana'], $this->defaultPluginCollection->getInstanceIds());
  }

  /**
   * @covers ::setConfiguration
   */
  public function testConfigurableSetConfiguration() {
    $this->setupPluginCollection($this->any());

    $this->defaultPluginCollection->setConfiguration(['apple' => ['value' => 'pineapple', 'id' => 'apple']]);
    $config = $this->defaultPluginCollection->getConfiguration();
    $this->assertSame(['apple' => ['value' => 'pineapple', 'id' => 'apple']], $config);
    $plugin = $this->pluginInstances['apple'];
    $this->assertSame(['apple' => ['value' => 'pineapple', 'id' => 'apple']], $plugin->getConfiguration());

    $this->defaultPluginCollection->setConfiguration([]);
    $this->assertSame([], $this->defaultPluginCollection->getConfiguration());

    $this->defaultPluginCollection->setConfiguration(['cherry' => ['value' => 'kiwi', 'id' => 'cherry']]);
    $expected['cherry'] = ['value' => 'kiwi', 'id' => 'cherry'];
    $config = $this->defaultPluginCollection->getConfiguration();
    $this->assertSame($expected, $config);
  }

  /**
   * @covers ::setConfiguration
   * @group legacy
   */
  public function testConfigurableSetConfigurationToNull(): void {
    $this->setupPluginCollection($this->any());

    $this->expectDeprecation('Calling Drupal\Core\Plugin\DefaultSingleLazyPluginCollection::setConfiguration() with a non-array argument is deprecated in drupal:10.3.0 and will fail in drupal:11.0.0. See https://www.drupal.org/node/3406191');
    $this->defaultPluginCollection->setConfiguration(NULL);
    $this->assertSame([], $this->defaultPluginCollection->getConfiguration());
  }

}

class ConfigurablePlugin extends PluginBase implements ConfigurableInterface {