Commit deb5565e authored by webchick's avatar webchick

Issue #2218033 by tim.plunkett: Move getOriginalId()/setOriginalId() to EntityInterface.

parent 2c2c1adc
......@@ -14,24 +14,6 @@
*/
interface ConfigEntityInterface extends EntityInterface {
/**
* Returns the original ID.
*
* @return string|null
* The original ID, if any.
*/
public function getOriginalId();
/**
* Sets the original ID.
*
* @param string $id
* The new ID to set as original ID.
*
* @return self
*/
public function setOriginalId($id);
/**
* Enables the configuration entity.
*
......
......@@ -307,8 +307,7 @@ public function save(EntityInterface $entity) {
}
if (!$config->isNew() && !isset($entity->original)) {
$this->resetCache(array($id));
$entity->original = $this->load($id);
$entity->original = $this->loadUnchanged($id);
}
// Build an ID if none is set.
......
......@@ -299,7 +299,11 @@ public function save(EntityInterface $entity) {
try {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityTypeId, $entity->id());
$id = $entity->id();
if ($entity->getOriginalId() !== NULL) {
$id = $entity->getOriginalId();
}
$entity->original = $this->loadUnchanged($id);
}
$entity->preSave($this);
......
......@@ -422,4 +422,20 @@ public function __sleep() {
return array_keys(get_object_vars($this));
}
/**
* {@inheritdoc}
*/
public function getOriginalId() {
// By default, entities do not support renames and do not have original IDs.
return NULL;
}
/**
* {@inheritdoc}
*/
public function setOriginalId($id) {
// By default, entities do not support renames and do not have original IDs.
return $this;
}
}
......@@ -297,4 +297,24 @@ public function getEntityType();
*/
public function referencedEntities();
/**
* Returns the original ID.
*
* @return int|string|null
* The original ID, if any. Entity types that do not support renames will
* never have an original ID and will return NULL.
*/
public function getOriginalId();
/**
* Sets the original ID.
*
* @param int|string|null $id
* The new ID to set as original ID. If the entity supports renames, setting
* NULL will prevent an update from being considered a rename.
*
* @return $this
*/
public function setOriginalId($id);
}
......@@ -536,7 +536,11 @@ public function save(EntityInterface $entity) {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityTypeId, $entity->id());
$id = $entity->id();
if ($entity->getOriginalId() !== NULL) {
$id = $entity->getOriginalId();
}
$entity->original = $this->loadUnchanged($id);
}
$entity->preSave($this);
......
......@@ -52,7 +52,11 @@ public function save(EntityInterface $entity) {
try {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityTypeId, $entity->id());
$id = $entity->id();
if ($entity->getOriginalId() !== NULL) {
$id = $entity->getOriginalId();
}
$entity->original = $this->loadUnchanged($id);
}
if ($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