function ConfigEntityStorage::doSave
Same name in other branches
- 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php \Drupal\Core\Config\Entity\ConfigEntityStorage::doSave()
- 10 core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php \Drupal\Core\Config\Entity\ConfigEntityStorage::doSave()
- 11.x core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php \Drupal\Core\Config\Entity\ConfigEntityStorage::doSave()
Overrides EntityStorageBase::doSave
File
-
core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityStorage.php, line 269
Class
- ConfigEntityStorage
- Defines the storage class for configuration entities.
Namespace
Drupal\Core\Config\EntityCode
protected function doSave($id, EntityInterface $entity) {
$is_new = $entity->isNew();
$prefix = $this->getPrefix();
$config_name = $prefix . $entity->id();
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage needs to access the original object.
// - The object needs to be renamed/copied in ConfigFactory and reloaded.
// - All instances of the object need to be renamed.
$this->configFactory
->rename($prefix . $id, $config_name);
}
$config = $this->configFactory
->getEditable($config_name);
// Retrieve the desired properties and set them in config.
$config->setData($this->mapToStorageRecord($entity));
$config->save($entity->hasTrustedData());
// Update the entity with the values stored in configuration. It is possible
// that configuration schema has casted some of the values.
if (!$entity->hasTrustedData()) {
$data = $this->mapFromStorageRecords([
$config->get(),
]);
$updated_entity = current($data);
foreach (array_keys($config->get()) as $property) {
$value = $updated_entity->get($property);
$entity->set($property, $value);
}
}
return $is_new ? SAVED_NEW : SAVED_UPDATED;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.