protected function importRevisionAsNew(&$entity_payload) { // Verify that the first revision can be used as a new revision. $first_revision = array(); $first_revision_key = ''; foreach ($entity_payload['revisions'] as $key => $revision) { $first_revision = $revision; $first_revision_key = $key; break; } // Make sure the first revision exists. if (count($first_revision) == 0 || $first_revision_key == '') { throw new InvalidEntityPayloadException('The entity does not exist, and there is no first revision to use.'); } // Make sure the first revision has no deletions. if (($message = $this->verifyRevisionPayload($first_revision)) !== true) { throw new InvalidRevisionPayloadException($message); } if (count($first_revision['deletions']) > 0) { throw new InvalidRevisionPayloadException('There are not supposed to be deletions for the first revision to use.'); } // Create the entity and apply the first revision. $entity = new Entity(new \stdClass(), $entity_payload['entity_type']); $entity->isNew(true); $result = $this->applyRevision($entity, $first_revision); // Finally, remove the first revision so we don't import it again. unset($entity_payload['revisions'][$first_revision_key]); // Add a success message to the transaction data. if ($result) { drupal_set_message("Created <strong>{$entity_payload['entity_type']}</strong> <code>{$entity_payload['uuid']}</code> successfully!"); } else { return false; } // Return the entity. return $entity; }