function ExecutablePluginBase::setConfig

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Executable/ExecutablePluginBase.php \Drupal\Core\Executable\ExecutablePluginBase::setConfig()
  2. 10 core/lib/Drupal/Core/Executable/ExecutablePluginBase.php \Drupal\Core\Executable\ExecutablePluginBase::setConfig()
  3. 11.x core/lib/Drupal/Core/Executable/ExecutablePluginBase.php \Drupal\Core\Executable\ExecutablePluginBase::setConfig()

Sets the value of a particular configuration option.

@todo This doesn't belong here. Move this into a new base class in https://www.drupal.org/node/1764380. @todo This does not set a value in \Drupal::config(), so the name is confusing.

Parameters

string $key: The key of the configuration option to set.

mixed $value: The value to set.

Return value

$this The executable object for chaining.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the provided configuration value does not pass validation.

File

core/lib/Drupal/Core/Executable/ExecutablePluginBase.php, line 81

Class

ExecutablePluginBase
Provides the basic architecture for executable plugins.

Namespace

Drupal\Core\Executable

Code

public function setConfig($key, $value) {
    if ($definition = $this->getConfigDefinition($key)) {
        $typed_data = \Drupal::typedDataManager()->create($definition, $value);
        if ($typed_data->validate()
            ->count() > 0) {
            throw new PluginException("The provided configuration value does not pass validation.");
        }
    }
    $this->configuration[$key] = $value;
    return $this;
}

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