Skip to content

Instantly share code, notes, and snippets.

@h3rj4n
Last active January 3, 2016 08:09
Show Gist options
  • Select an option

  • Save h3rj4n/8433871 to your computer and use it in GitHub Desktop.

Select an option

Save h3rj4n/8433871 to your computer and use it in GitHub Desktop.
<?php
// DatabaseStorateController::save()
public function save(EntityInterface $entity) {
$transaction = $this->database->startTransaction();
try {
// Load the stored entity, if any.
if (!$entity->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityType, $entity->id());
}
$entity->preSave($this);
$this->invokeHook('presave', $entity);
if (!$entity->isNew()) {
// It's about his part. The entity is send directly to the drupal_write_record function
$return = drupal_write_record($this->entityInfo->getBaseTable(), $entity, $this->idKey);
$this->resetCache(array($entity->id()));
$entity->postSave($this, TRUE);
$this->invokeHook('update', $entity);
}
else {
// .. doing stuff
}
// .. doing more stuff
}
catch (\Exception $e) {
// .. more
}
}
// FieldableDatabaseStorageController::save()
public function save(EntityInterface $entity) {
// .. doing stuff
// Create the storage record to be saved.
$record = $this->mapToStorageRecord($entity);
if (!$entity->isNew()) {
if ($entity->isDefaultRevision()) {
// Here there is a record inserted instead of the entity.
$return = drupal_write_record($this->entityInfo->getBaseTable(), $record, $this->idKey);
}
else {
// .. doing stuff
}
// .. doing a lot!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment