diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 67405415aa70466562e97c1e4da503930cc43209..0ca35a539caa45baee737f59fcddc66ccc5593a4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -130,9 +130,13 @@ public function getOriginalId() { * {@inheritdoc} */ public function setOriginalId($id) { + // Do not call the parent method since that would mark this entity as no + // longer new. Unlike content entities, new configuration entities have an + // ID. + // @todo https://www.drupal.org/node/2478811 Document the entity life cycle + // and the differences between config and content. $this->originalId = $id; - - return parent::setOriginalId($id); + return $this; } /** diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 4636c2a28c73b0aba3f45cf9e2c472b883c2bcc3..ca17e6410f8a77bb3cd03a7c7d1c49be510fb572 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -472,7 +472,6 @@ public function __sleep() { * {@inheritdoc} */ public function __wakeup() { - $is_new = $this->isNew(); // Determine what were the properties from toArray() that were saved in // __sleep(). $keys = $this->_serializedKeys; @@ -481,7 +480,6 @@ public function __wakeup() { // Run those values through the __construct(), as if they came from a // regular entity load. $this->__construct($values, $this->entityTypeId); - $this->enforceIsNew($is_new); } } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 9456d33c81c56d7f5096b15379b808b45e83268a..caf51ddcbbb508910df1154445cf996eaeba7846 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -7,9 +7,7 @@ namespace Drupal\Tests\Core\Config\Entity; -use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Language\Language; use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin; use Drupal\Tests\UnitTestCase; @@ -317,6 +315,15 @@ public function testGetOriginalId() { $this->assertSame($this->id, $this->entity->getOriginalId()); $this->assertSame($this->entity, $this->entity->setOriginalId($new_id)); $this->assertSame($new_id, $this->entity->getOriginalId()); + + // Check that setOriginalId() does not change the entity "isNew" status. + $this->assertFalse($this->entity->isNew()); + $this->entity->setOriginalId($this->randomMachineName()); + $this->assertFalse($this->entity->isNew()); + $this->entity->enforceIsNew(); + $this->assertTrue($this->entity->isNew()); + $this->entity->setOriginalId($this->randomMachineName()); + $this->assertTrue($this->entity->isNew()); } /**