You are here

public function MetaTagDownloadForm::metatagImportExportCsvDownload in Metatag Import Export CSV 8

Gets list of all entity and passes to batch.

1 call to MetaTagDownloadForm::metatagImportExportCsvDownload()
MetaTagDownloadForm::submitForm in src/Form/MetaTagDownloadForm.php
Form submission handler.

File

src/Form/MetaTagDownloadForm.php, line 148

Class

MetaTagDownloadForm
Defines a form that configures forms module settings.

Namespace

Drupal\metatag_import_export_csv\Form

Code

public function metatagImportExportCsvDownload($entity_type, $bundles, $tags, $delimiter) {
  $query = \Drupal::entityQuery($entity_type);
  $entity_type_definition = \Drupal::service('entity_type.manager')
    ->getDefinition($entity_type);
  if ($bundle_key = $entity_type_definition
    ->getKey('bundle')) {
    $query
      ->condition($bundle_key, $bundles, 'IN');
  }

  // TODO: Generalise this.
  switch ($entity_type) {
    case 'node':
      $query
        ->sort('created', 'ASC');
      break;
  }
  $nidlist = $query
    ->execute();
  $nidlist = array_values($nidlist);
  $total_count = count($nidlist);
  $operations = [];
  for ($i = 0; $i < $total_count; $i++) {
    $operations[] = [
      '\\Drupal\\metatag_import_export_csv\\MetatagExport::generateExportCsv',
      [
        $nidlist[$i],
        $entity_type,
        $tags,
        $delimiter,
      ],
    ];
  }
  $batch = [
    'operations' => $operations,
    'finished' => '\\Drupal\\metatag_import_export_csv\\MetatagExport::downloadCsv',
    'title' => $this
      ->t('Metatags export'),
    'init_message' => $this
      ->t('Export process is starting.'),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('Batch has encountered an error.'),
  ];
  batch_set($batch);
}