You are here

public static function EntityExportCsvBatch::finished in Entity Export CSV 8

The finished callback for the entity content export.

Parameters

bool $success: A boolean if the batch process was successful.

array $results: An array of results for the given batch process.

array $operations: An array of batch operations that were performed.

File

src/EntityExportCsvBatch.php, line 238

Class

EntityExportCsvBatch
Define entity export csv batch.

Namespace

Drupal\entity_export_csv

Code

public static function finished($success, array $results, array $operations) {
  if ($success && isset($results['file_uri']) && file_exists($results['file_uri'])) {
    $file_uri = $results['file_uri'];
    $token = static::getToken($file_uri);
    $query_options = [
      'query' => [
        'token' => $token,
        'file' => $file_uri,
      ],
    ];
    $download_url = Url::fromRoute('entity_export_csv.download', [], $query_options)
      ->toString();
    \Drupal::messenger()
      ->addStatus(t("Export successful. The download should automatically start shortly. If it doesn't, click <a data-auto-download href='@download_url'>Download</a>.", [
      '@download_url' => $download_url,
    ]));
  }
  else {
    $message = t('An error has occurred. Please contact an administrator.');
    \Drupal::messenger()
      ->addError($message);
  }
}