You are here

function gathercontent_upload_process in GatherContent 8.5

Same name and namespace in other branches
  1. 8.3 gathercontent.module \gathercontent_upload_process()
  2. 7.3 gathercontent.module \gathercontent_upload_process()

Upload batch operation callback.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Object of entity we want to upload.

\Drupal\gathercontent\Entity\MappingInterface $mapping: Mapping object.

int|null $gcId: GatherContent ID.

array $context: Context of operation.

2 string references to 'gathercontent_upload_process'
ContentUploadSelectForm::submitForm in gathercontent_upload_ui/src/Form/ContentUploadSelectForm.php
Form submission handler.
drush_gathercontent_upload in gathercontent_upload/gathercontent_upload.drush.inc
Implements drush_COMMAND().

File

gathercontent_upload/gathercontent_upload.module, line 23
Main module file for GatherContent Upload module.

Code

function gathercontent_upload_process(EntityInterface $entity, MappingInterface $mapping, $gcId = NULL, &$context = []) {

  /** @var \Drupal\gathercontent_upload\Export\Exporter $exporter */
  $exporter = \Drupal::service('gathercontent_upload.exporter');
  if (!isset($context['results']['success'])) {
    $context['results']['success'] = 0;
  }
  if (!isset($context['results']['failed'])) {
    $context['results']['failed'] = 0;
  }
  try {
    $exporter
      ->export($entity, $mapping, $gcId, $context);
    $context['results']['success']++;
  } catch (\Exception $e) {
    $context['results']['messages'][] = $e
      ->getMessage();
    $context['results']['failed']++;
  }
}