Commit 1f9eabbd authored by xjm's avatar xjm
Browse files

Issue #2405165 by yched, alexpott, xjm: Entity::setOriginalId() does...

Issue #2405165 by yched, alexpott, xjm: Entity::setOriginalId() does enforceIsNew(FALSE), that is wrong for ConfigEntities
parent b838fd5f
......@@ -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;
}
/**
......
......@@ -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);
}
}
......@@ -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());
}
/**
......
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