diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 385ef48..a53fbfc 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -823,6 +823,7 @@ function menu_link_rebuild_defaults() { $link['customized'] = $existing_item->customized; $link['updated'] = $existing_item->updated; $menu_link = $menu_link_storage->createFromDefaultLink($link); + $menu_link->enforceIsNew(FALSE); // Convert the existing item to a typed object. /** @var \Drupal\menu_link\MenuLinkInterface $existing_item */ diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 992c728..456bc83 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -894,6 +894,7 @@ public function createDuplicate() { $duplicate = clone $this; $entity_type = $this->getEntityType(); $duplicate->{$entity_type->getKey('id')}->value = NULL; + $duplicate->enforceIsNew(); // Check if the entity type supports UUIDs and generate a new one if so. if ($entity_type->hasKey('uuid')) { diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 0c2bfe4..cf43ee6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -67,6 +67,7 @@ public function create(array $values = array()) { $bundle = $values[$this->bundleKey]; } $entity = new $entity_class(array(), $this->entityTypeId, $bundle); + $entity->enforceIsNew(); foreach ($entity as $name => $field) { if (isset($values[$name])) { diff --git a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php index c25ff56..180dfef 100644 --- a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php @@ -238,6 +238,7 @@ public function create(array $values = array()) { $entity_class::preCreate($this, $values); $entity = new $entity_class($values, $this->entityTypeId); + $entity->enforceIsNew(); // Assign a new UUID if there is none yet. if ($this->uuidKey && !isset($entity->{$this->uuidKey})) { diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index c3b4981..ccbc098 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1282,6 +1282,7 @@ function comment_prepare_author(CommentInterface $comment) { $account = $comment->getOwner(); if (empty($account->uid->value)) { $account = entity_create('user', array('uid' => 0, 'name' => $comment->getAuthorName(), 'homepage' => $comment->getHomepage())); + $account->enforceIsNew(FALSE); } return $account; } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 9e42126..cee670a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -230,6 +230,7 @@ function testFieldAttachCache() { 'type' => $entity_type, 'id' => $entity->id(), )); + $entity->enforceIsNew(FALSE); $entity->{$this->field_name_2} = $values; $entity->save(); $this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no cache entry on update'); @@ -245,6 +246,7 @@ function testFieldAttachCache() { 'type' => $entity_type, 'id' => $entity->id(), )); + $entity->enforceIsNew(FALSE); $values = $this->_generateTestFieldValues($this->field_2->getCardinality()); $entity->{$this->field_name_2} = $values; $entity->setNewRevision(); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index efb6ae8..36017b0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -182,6 +182,7 @@ function testFieldAttachSaveEmptyData() { $this->createFieldWithInstance('', $entity_type); $entity_init = entity_create($entity_type, array('id' => 1)); + $entity_init->enforceIsNew(FALSE); // Insert: Field is NULL. $entity = clone $entity_init; diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 2543616..2aeaed2 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -179,6 +179,7 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN $existing = reset($existing_files); $file->fid = $existing->id(); $file->setFilename($existing->getFilename()); + $file->enforceIsNew(FALSE); } } // If we are renaming around an existing file (rather than a directory), @@ -527,6 +528,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM $existing = reset($existing_files); $file->fid = $existing->id(); $file->setFilename($existing->getFilename()); + $file->enforceIsNew(FALSE); } } // If we are renaming around an existing file (rather than a directory), @@ -952,6 +954,7 @@ function file_save_upload($form_field_name, array &$form_state, $validators = ar if (count($existing_files)) { $existing = reset($existing_files); $file->fid = $existing->id(); + $file->enforceIsNew(FALSE); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php index c777691..00f4cb7 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php @@ -165,7 +165,9 @@ function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { $file['fid'] = db_insert('file_managed') ->fields($file) ->execute(); - return entity_create('file', $file); + $file_entity = entity_create('file', $file); + $file_entity->enforceIsNew(FALSE); + return $file_entity; } /** diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php index c9ec86d..feb3701 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php @@ -174,7 +174,9 @@ function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { // the hooks. $this->assertNotIdentical(drupal_write_record('file_managed', $file), FALSE, 'The file was added to the database.', 'Create test file'); - return entity_create('file', (array) $file); + $file_entity = entity_create('file', (array) $file); + $file_entity->enforceIsNew(FALSE); + return $file_entity; } /**