diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 67405415aa7..0ca35a539ca 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -130,9 +130,13 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface * {@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 4636c2a28c7..ca17e6410f8 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -472,7 +472,6 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl * {@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 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl // 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 9456d33c81c..caf51ddcbbb 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 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { $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()); } /**