You are here

public function EntityPublisher::saveEntity in Content Synchronizer 8

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

Save the entity after import.

If the entity is revisionable, it creates a new revision. If the entity is new and is a root entity, then it is unpublished.

File

src/Service/EntityPublisher.php, line 22

Class

EntityPublisher
THe entity publsher service.

Namespace

Drupal\content_synchronizer\Service

Code

public function saveEntity(Entity $entity, $gid = NULL, $existingEntity = NULL, array $dataToImport = []) {

  // Alter entity before import.
  $entityDataToImport = array_key_exists('translations', $dataToImport) ? $dataToImport['translations'][$entity
    ->language()
    ->getId()] : $dataToImport;
  \Drupal::moduleHandler()
    ->alter(EntityProcessorBase::IMPORT_HOOK, $entity, $existingEntity, $entityDataToImport);

  // Try to create a new revision of the current entity.
  $this
    ->saveEntityWithRevision($entity, $gid, $existingEntity);
}