function Config::save

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/Config.php \Drupal\Core\Config\Config::save()
  2. 10 core/lib/Drupal/Core/Config/Config.php \Drupal\Core\Config\Config::save()
  3. 9 core/lib/Drupal/Core/Config/Config.php \Drupal\Core\Config\Config::save()
  4. 8.9.x core/lib/Drupal/Core/Config/Config.php \Drupal\Core\Config\Config::save()

Saves the configuration object.

Must invalidate the cache tags associated with the configuration object.

Parameters

bool $has_trusted_data: Set to TRUE if the configuration data has already been checked to ensure it conforms to schema. Generally this is only used during module and theme installation. This argument is deprecated in Drupal 11.4.0 and is removed in Drupal 13.0.0.

Return value

$this

Overrides StorableConfigBase::save

1 method overrides Config::save()
ImmutableConfig::save in core/lib/Drupal/Core/Config/ImmutableConfig.php
Saves the configuration object.

File

core/lib/Drupal/Core/Config/Config.php, line 201

Class

Config
Defines the default configuration object.

Namespace

Drupal\Core\Config

Code

public function save($has_trusted_data = FALSE) {
  if (func_num_args() > 0) {
    @trigger_error('Calling ' . __METHOD__ . '() with the $has_trusted_data argument is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3348180', E_USER_DEPRECATED);
  }
  // Validate the configuration object name before saving.
  static::validateName($this->name);
  // If there is a schema for this configuration object, cast all values to
  // conform to the schema.
  if (!$has_trusted_data) {
    if ($this->typedConfigManager
      ->hasConfigSchema($this->name)) {
      // Ensure that the schema wrapper has the latest data.
      $this->schemaWrapper = NULL;
      $this->data = $this->castValue(NULL, $this->data);
      // Reclaim the memory used by the schema wrapper.
      $this->schemaWrapper = NULL;
    }
    else {
      foreach ($this->data as $key => $value) {
        $this->validateValue($key, $value);
      }
    }
  }
  // Potentially configuration schema could have changed the underlying data's
  // types.
  $this->resetOverriddenData();
  $this->storage
    ->write($this->name, $this->data);
  if (!$this->isNew) {
    Cache::invalidateTags($this->getCacheTags());
  }
  $this->isNew = FALSE;
  $event_name = $this->getStorage()
    ->getCollectionName() === StorageInterface::DEFAULT_COLLECTION ? ConfigEvents::SAVE : ConfigCollectionEvents::SAVE_IN_COLLECTION;
  $this->eventDispatcher
    ->dispatch(new ConfigCrudEvent($this), $event_name);
  $this->originalData = $this->data;
  return $this;
}

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