Config::save

public Config::save($has_trusted_data = FALSE)

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.

Return value

$this

Overrides StorableConfigBase::save

See also

\Drupal\Core\Config\ConfigInstaller::createConfiguration()

File

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

Class

Config
Defines the default configuration object.

Namespace

Drupal\Core\Config

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public function save($has_trusted_data = FALSE) {
  // 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;
      foreach ($this->data as $key => $value) {
        $this->data[$key] = $this->castValue($key, $value);
      }
    }
    else {
      foreach ($this->data as $key => $value) {
        $this->validateValue($key, $value);
      }
    }
  }
 
  $this->storage->write($this->name, $this->data);
  if (!$this->isNew) {
    Cache::invalidateTags($this->getCacheTags());
  }
  $this->isNew = FALSE;
  $this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this));
  $this->originalData = $this->data;
  // Potentially configuration schema could have changed the underlying data's
  // types.
  $this->resetOverriddenData();
  return $this;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.