function DefaultLazyPluginCollection::setInstanceConfiguration

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php \Drupal\Core\Plugin\DefaultLazyPluginCollection::setInstanceConfiguration()
  2. 8.9.x core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php \Drupal\Core\Plugin\DefaultLazyPluginCollection::setInstanceConfiguration()
  3. 10 core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php \Drupal\Core\Plugin\DefaultLazyPluginCollection::setInstanceConfiguration()

Updates the configuration for a plugin instance.

If there is no plugin instance yet, a new will be instantiated. Otherwise, the existing instance is updated with the new configuration.

Parameters

string $instance_id: The ID of a plugin to set the configuration for.

array $configuration: The plugin configuration to set.

2 calls to DefaultLazyPluginCollection::setInstanceConfiguration()
DefaultLazyPluginCollection::addInstanceId in core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php
DefaultLazyPluginCollection::setConfiguration in core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php

File

core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php, line 158

Class

DefaultLazyPluginCollection
Provides a default plugin collection for a plugin type.

Namespace

Drupal\Core\Plugin

Code

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) {
        $instance->setConfiguration($configuration);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.