You are here

protected function EntityPublisher::saveEntityWithRevision in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Service/EntityPublisher.php \Drupal\content_synchronizer\Service\EntityPublisher::saveEntityWithRevision()
  2. 3.x src/Service/EntityPublisher.php \Drupal\content_synchronizer\Service\EntityPublisher::saveEntityWithRevision()

Try to create a revision of the entity.

Parameters

\Drupal\Core\Entity\Entity $entity: The entity to save.

string $gid: THe gid.

\Drupal\Core\Entity\Entity $existingEntity: The existing entity before changes.

1 call to EntityPublisher::saveEntityWithRevision()
EntityPublisher::saveEntity in src/Service/EntityPublisher.php
Save the entity after import.

File

src/Service/EntityPublisher.php, line 44

Class

EntityPublisher
THe entity publsher service.

Namespace

Drupal\content_synchronizer\Service

Code

protected function saveEntityWithRevision(Entity $entity, $gid, Entity $existingEntity = NULL) {
  if ($entity
    ->id()) {
    $entityMethods = get_class_methods($entity);
    if (in_array('setRevisionCreationTime', $entityMethods) && in_array('setNewRevision', $entityMethods)) {
      try {
        $revision = clone $entity;
        $revision
          ->setNewRevision(TRUE);
        $revision->revision_log = '[Content Synchronizer] ' . ImportProcessor::getCurrentImportProcessor()
          ->getImport()
          ->label();
        $revision
          ->setRevisionCreationTime(time());
        if ($this
          ->haveToSave($revision, $existingEntity)) {
          $revision
            ->save();
        }
      } catch (\Exception $e) {
        $this
          ->saveEntityWithUnpublishedStatus($entity, $gid, $existingEntity);
      }
    }
    else {
      $this
        ->saveEntityWithUnpublishedStatus($entity, $gid, $existingEntity);
    }
  }
  else {
    $this
      ->saveEntityWithUnpublishedStatus($entity, $gid, $existingEntity);
  }
}