function SimpleConfigUpdate::apply

Same name in other branches
  1. 10 core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/SimpleConfigUpdate.php \Drupal\Core\Config\Action\Plugin\ConfigAction\SimpleConfigUpdate::apply()

Overrides ConfigActionPluginInterface::apply

File

core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/SimpleConfigUpdate.php, line 46

Class

SimpleConfigUpdate
@internal This API is experimental.

Namespace

Drupal\Core\Config\Action\Plugin\ConfigAction

Code

public function apply(string $configName, mixed $value) : void {
    $config = $this->configFactory
        ->getEditable($configName);
    // @todo https://www.drupal.org/i/3439713 Should we error if this is a
    //   config entity?
    if ($config->isNew()) {
        throw new ConfigActionException(sprintf('Config %s does not exist so can not be updated', $configName));
    }
    // Expect $value to be an array whose keys are the config keys to update.
    if (!is_array($value)) {
        throw new ConfigActionException(sprintf('Config %s can not be updated because $value is not an array', $configName));
    }
    foreach ($value as $key => $value) {
        $config->set($key, $value);
    }
    $config->save();
}

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