You are here

public function MetaTagUploadForm::metatagImportExportCsvUpload in Metatag Import Export CSV 8

Reads ech line form csv and passes it to batch.

1 call to MetaTagUploadForm::metatagImportExportCsvUpload()
MetaTagUploadForm::submitForm in src/Form/MetaTagUploadForm.php
Form submission handler.

File

src/Form/MetaTagUploadForm.php, line 60

Class

MetaTagUploadForm
Form for uploading csv.

Namespace

Drupal\metatag_import_export_csv\Form

Code

public function metatagImportExportCsvUpload($filepath) {
  $handle = fopen($filepath, 'r');
  $headers = fgetcsv($handle);
  fclose($handle);
  $operations = [];
  $operations[] = [
    '\\Drupal\\metatag_import_export_csv\\MetatagImport::importCsvBatchOperation',
    [
      $headers,
      $filepath,
    ],
  ];
  $batch = [
    'operations' => $operations,
    'finished' => '\\Drupal\\metatag_import_export_csv\\MetatagImport::importFinish',
    'title' => $this
      ->t('Metatags import'),
    'init_message' => $this
      ->t('Import process is starting.'),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('Batch has encountered an error.'),
  ];
  batch_set($batch);
}