Last active
January 3, 2016 08:09
-
-
Save h3rj4n/8433871 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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