You are here

public static function WebformResultsExportController::batchSet in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Controller/WebformResultsExportController.php \Drupal\webform\Controller\WebformResultsExportController::batchSet()

Batch API; Initialize batch operations.

Parameters

\Drupal\webform\WebformInterface|null $webform: A webform.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A webform source entity.

array $export_options: An array of export options.

See also

http://www.jeffgeerling.com/blogs/jeff-geerling/using-batch-api-build-hu...

2 calls to WebformResultsExportController::batchSet()
WebformCliService::drush_webform_export in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().
WebformResultsExportController::index in src/Controller/WebformResultsExportController.php
Returns webform submission as a CSV.

File

src/Controller/WebformResultsExportController.php, line 220

Class

WebformResultsExportController
Controller routines for webform submission export.

Namespace

Drupal\webform\Controller

Code

public static function batchSet(WebformInterface $webform, EntityInterface $source_entity = NULL, array $export_options) {
  if (!empty($export_options['excluded_columns']) && is_string($export_options['excluded_columns'])) {
    $excluded_columns = explode(',', $export_options['excluded_columns']);
    $export_options['excluded_columns'] = array_combine($excluded_columns, $excluded_columns);
  }

  /** @var \Drupal\webform\WebformSubmissionExporterInterface $submission_exporter */
  $submission_exporter = \Drupal::service('webform_submission.exporter');
  $submission_exporter
    ->setWebform($webform);
  $submission_exporter
    ->setSourceEntity($source_entity);
  $submission_exporter
    ->setExporter($export_options);
  $parameters = [
    $webform,
    $source_entity,
    $export_options,
  ];
  $batch = [
    'title' => t('Exporting submissions'),
    'init_message' => t('Creating export file'),
    'error_message' => t('The export file could not be created because an error occurred.'),
    'operations' => [
      [
        [
          '\\Drupal\\webform\\Controller\\WebformResultsExportController',
          'batchProcess',
        ],
        $parameters,
      ],
    ],
    'finished' => [
      '\\Drupal\\webform\\Controller\\WebformResultsExportController',
      'batchFinish',
    ],
  ];
  batch_set($batch);
}