Issue #2405165 by yched, alexpott, xjm: Entity::setOriginalId() does enforceIsNew(FALSE), that is wrong for ConfigEntities
parent
b838fd5f09
commit
1f9eabbd92
|
@ -130,9 +130,13 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setOriginalId($id) {
|
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;
|
$this->originalId = $id;
|
||||||
|
return $this;
|
||||||
return parent::setOriginalId($id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -472,7 +472,6 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __wakeup() {
|
public function __wakeup() {
|
||||||
$is_new = $this->isNew();
|
|
||||||
// Determine what were the properties from toArray() that were saved in
|
// Determine what were the properties from toArray() that were saved in
|
||||||
// __sleep().
|
// __sleep().
|
||||||
$keys = $this->_serializedKeys;
|
$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
|
// Run those values through the __construct(), as if they came from a
|
||||||
// regular entity load.
|
// regular entity load.
|
||||||
$this->__construct($values, $this->entityTypeId);
|
$this->__construct($values, $this->entityTypeId);
|
||||||
$this->enforceIsNew($is_new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\Tests\Core\Config\Entity;
|
namespace Drupal\Tests\Core\Config\Entity;
|
||||||
|
|
||||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||||
use Drupal\Component\Plugin\PluginBase;
|
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
|
use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
@ -317,6 +315,15 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||||
$this->assertSame($this->id, $this->entity->getOriginalId());
|
$this->assertSame($this->id, $this->entity->getOriginalId());
|
||||||
$this->assertSame($this->entity, $this->entity->setOriginalId($new_id));
|
$this->assertSame($this->entity, $this->entity->setOriginalId($new_id));
|
||||||
$this->assertSame($new_id, $this->entity->getOriginalId());
|
$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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue