diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index a7eb48e..a4eb00d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -505,13 +505,13 @@ protected function preSave(EntityInterface $entity) { ->execute(); $matched_entity = reset($matching_entities); if (!empty($matched_entity) && ($matched_entity != $entity->id())) { - throw new ConfigUUIDException(sprintf('Attempt to save a configuration object %s with UUID %s when this UUID is already used for %s', $this->id(), $this->uuid(), $matched_entity)); + throw new ConfigUUIDException(sprintf('Attempt to save a configuration object %s with UUID %s when this UUID is already used for %s', $entity->id(), $entity->uuid(), $matched_entity)); } if (!$entity->isNew()) { $original = $this->loadUnchanged($entity->id()); // Ensure that the UUID cannot be changed for an existing entity. - if ($original && $original->uuid() != $entity->uuid()) { + if ($original && ($original->uuid() != $entity->uuid())) { throw new ConfigUUIDException(sprintf('Attempt to save a configuration entity %s with UUID %s when this entity already exists with UUID %s', $entity->id(), $entity->uuid(), $original->uuid())); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index e2e910f..a50db92 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -159,6 +159,8 @@ function testCRUD() { $this->assertIdentical($same_id->label(), ''); $this->assertNotEqual($same_id->uuid(), $config_test->uuid()); + // Delete the overridden entity first. + $same_id->delete(); // Revert to previous state. $config_test->save(); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php index 6a86adf..97144aa 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php @@ -179,6 +179,8 @@ protected function displayTests() { $executable->initDisplay(); $this->assertTrue($executable->displayHandlers->get($new_id) instanceof Page, 'New page display "test" uses the right display plugin.'); + // To save this with a new ID, we should use createDuplicate(). + $view = $view->createDuplicate(); $view->set('id', 'test_view_storage_new_new2'); $view->save(); $values = config('views.view.test_view_storage_new_new2')->get(); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php index 5e7666c..687b233 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php @@ -74,8 +74,9 @@ protected function actions(array $form, array &$form_state) { * Overrides \Drupal\Core\Entity\EntityFormController::form(). */ public function submit(array $form, array &$form_state) { - $this->entity = parent::submit($form, $form_state); - $this->entity->setOriginalID(NULL); + $original = parent::submit($form, $form_state); + $this->entity = $original->createDuplicate(); + $this->entity->set('id', $form_state['values']['id']); $this->entity->save(); // Redirect the user to the view admin form.