Skip to content
Snippets Groups Projects
Verified Commit b7c0549a authored by Dave Long's avatar Dave Long
Browse files

Issue #3445950 by alexpott, tim.plunkett:...

Issue #3445950 by alexpott, tim.plunkett: \Drupal\Core\Plugin\DefaultLazyPluginCollection::setInstanceConfiguration() assumes that $configuration results in the same plugin instance

(cherry picked from commit 926d069c)
parent d45f21b7
No related branches found
No related tags found
4 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!8325Update file Sort.php,!8095Expose document root on install
Pipeline #169834 passed
Pipeline: drupal

#169862

    Pipeline: drupal

    #169858

      Pipeline: drupal

      #169849

        +1
        ......@@ -161,6 +161,17 @@ public function setConfiguration($configuration) {
        * The plugin configuration to set.
        */
        public function setInstanceConfiguration($instance_id, array $configuration) {
        if (
        isset($this->pluginInstances[$instance_id]) &&
        isset($configuration[$this->pluginKey]) &&
        isset($this->configurations[$instance_id][$this->pluginKey]) &&
        $configuration[$this->pluginKey] !== $this->configurations[$instance_id][$this->pluginKey]
        ) {
        // If the plugin has already been instantiated by the configuration was
        // for a different plugin then we need to unset the instantiated plugin.
        unset($this->pluginInstances[$instance_id]);
        }
        $this->configurations[$instance_id] = $configuration;
        $instance = $this->get($instance_id);
        if ($instance instanceof ConfigurableInterface) {
        ......
        ......@@ -168,6 +168,37 @@ public function testSetInstanceConfiguration() {
        $this->assertSame($expected, $config['cherry']);
        }
        /**
        * Tests plugin instances are changed if the configuration plugin key changes.
        *
        * @covers ::setInstanceConfiguration
        */
        public function testSetInstanceConfigurationPluginChange() {
        $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 = [
        'instance' => $configurable_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->assertInstanceOf(ConfigurableInterface::class, $collection->get('instance'));
        // Ensure changing the instance to a different plugin via
        // setInstanceConfiguration() results in a different plugin instance.
        $collection->setInstanceConfiguration('instance', $nonconfigurable_config);
        $this->assertNotInstanceOf(ConfigurableInterface::class, $collection->get('instance'));
        }
        /**
        * @covers ::count
        */
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment