protected EntityStorageBase::doPreSave(EntityInterface $entity)
Performs presave entity processing.
\Drupal\Core\Entity\EntityInterface $entity: The saved entity.
int|string The processed entity identifier.
\Drupal\Core\Entity\EntityStorageException If the entity identifier is invalid.
protected function doPreSave(EntityInterface $entity) { $id = $entity->id(); // Track the original ID. if ($entity->getOriginalId() !== NULL) { $id = $entity->getOriginalId(); } // Track if this entity exists already. $id_exists = $this->has($id, $entity); // A new entity should not already exist. if ($id_exists && $entity->isNew()) { throw new EntityStorageException("'{$this->entityTypeId}' entity with ID '$id' already exists."); } // Load the original entity, if any. if ($id_exists && !isset($entity->original)) { $entity->original = $this->loadUnchanged($id); } // Allow code to run before saving. $entity->preSave($this); $this->invokeHook('presave', $entity); return $id; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityStorageBase.php/function/EntityStorageBase::doPreSave/8.1.x