Commit 04abeabd authored by webchick's avatar webchick

Issue #2217975 by tim.plunkett: ConfigEntityBase::preSave() doesn't properly...

Issue #2217975 by tim.plunkett: ConfigEntityBase::preSave() doesn't properly support renames; ConfigStorageController::save() preforms renames too early.
parent 2ca54697
......@@ -230,7 +230,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
->condition('uuid', $this->uuid())
->execute();
$matched_entity = reset($matching_entities);
if (!empty($matched_entity) && ($matched_entity != $this->id())) {
if (!empty($matched_entity) && ($matched_entity != $this->id()) && $matched_entity != $this->getOriginalId()) {
throw new ConfigDuplicateUUIDException(format_string('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity)));
}
......
......@@ -311,14 +311,6 @@ public function save(EntityInterface $entity) {
$entity->original = $this->load($id);
}
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage controller 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.
$config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
}
// Build an ID if none is set.
if (!isset($entity->{$this->idKey})) {
$entity->{$this->idKey} = $entity->id();
......@@ -327,6 +319,14 @@ public function save(EntityInterface $entity) {
$entity->preSave($this);
$this->invokeHook('presave', $entity);
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage controller 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.
$config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
}
// Retrieve the desired properties and set them in config.
foreach ($entity->getExportProperties() as $key => $value) {
$config->set($key, $value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment