1 node.entity.inc | public NodeStorageController::save(EntityInterface $entity) |
Overrides EntityDatabaseStorageController::save().
Parameters
Node $entity: The node entity being saved.
Overrides EntityDatabaseStorageController::save
File
- core/
modules/ node/ node.entity.inc, line 463 - Entity controller and class for nodes.
Class
- NodeStorageController
- Controller class for nodes.
Code
public function save(EntityInterface $entity) {
$transaction = db_transaction();
try {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityType, $entity->id());
}
$this->preSave($entity);
$this->invokeHook('presave', $entity);
if ($entity->isNew()) {
$op = 'insert';
$return = backdrop_write_record($this->entityInfo['base table'], $entity);
unset($entity->is_new);
}
else {
$op = 'update';
// Update the base node table, but only if this revision is marked as
// the active revision.
if ($entity->isActiveRevision()) {
$return = backdrop_write_record($this->entityInfo['base table'], $entity, $this->idKey);
}
else {
$return = SAVED_UPDATED;
}
}
if ($this->revisionKey) {
$this->saveRevision($entity);
}
// Reset the persistent and static cache for this node.
if ($op == 'update') {
$this->resetCache(array($entity->{$this->idKey}));
}
$this->postSave($entity, $op == 'update');
$this->invokeHook($op, $entity);
// Ignore replica server temporarily.
db_ignore_replica();
unset($entity->original);
return $return;
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception($this->entityType, $e);
throw new EntityStorageException($e->getMessage(), (int) $e->getCode(), $e);
}
}