You are here

public static function YamlFormResultsExportController::batchSet in YAML Form 8

Batch API; Initialize batch operations.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: A form.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A form 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 YamlFormResultsExportController::batchSet()
drush_yamlform_export in drush/yamlform.drush.inc
Implements drush_hook_COMMAND().
YamlFormResultsExportController::index in src/Controller/YamlFormResultsExportController.php
Returns form submission as a CSV.

File

src/Controller/YamlFormResultsExportController.php, line 228

Class

YamlFormResultsExportController
Controller routines for form submission export.

Namespace

Drupal\yamlform\Controller

Code

public static function batchSet(YamlFormInterface $yamlform, 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\yamlform\YamlFormSubmissionExporterInterface $submission_exporter */
  $submission_exporter = \Drupal::service('yamlform_submission.exporter');
  $submission_exporter
    ->setYamlForm($yamlform);
  $submission_exporter
    ->setSourceEntity($source_entity);
  $submission_exporter
    ->setExporter($export_options);
  $parameters = [
    $yamlform,
    $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\\yamlform\\Controller\\YamlFormResultsExportController',
          'batchProcess',
        ],
        $parameters,
      ],
    ],
    'finished' => [
      '\\Drupal\\yamlform\\Controller\\YamlFormResultsExportController',
      'batchFinish',
    ],
  ];
  batch_set($batch);
}