You are here

public function EntityExportCsvDownload::resultsExport in Entity Export CSV 8

Build the results page.

Return value

array A Drupal render array.

File

src/Controller/EntityExportCsvDownload.php, line 65

Class

EntityExportCsvDownload
Define the entity export csv download controller.

Namespace

Drupal\entity_export_csv\Controller

Code

public function resultsExport() {
  $request = $this
    ->getRequest();
  if (!$request->query
    ->has('results')) {
    throw new NotFoundHttpException($this
      ->t('Missing export download results.'));
  }
  $results = $request->query
    ->get('results');
  $file_uri = isset($results['file']) ? $results['file'] : NULL;
  $token = $this->csrfToken
    ->get($file_uri);
  $query_options = [
    'query' => [
      'token' => $token,
      'file' => $file_uri,
    ],
  ];
  $download_url = Url::fromRoute('entity_content_export.download', [], $query_options)
    ->toString();
  $build['results'] = [
    '#markup' => $this
      ->t("The download should automatically start shortly. If it doesn't, click\n         <a data-auto-download href='@download_url'>Download</a>.", [
      '@download_url' => $download_url,
    ]),
    '#attached' => [
      'library' => [
        'entity_content_csv/auto-download',
      ],
    ],
  ];
  $build['actions'] = [
    '#type' => 'actions',
  ];
  $build['actions']['back'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Back to Export page.'),
    '#url' => Url::fromRoute('entity_export_csv.export_form'),
    '#options' => [
      'attributes' => [
        'class' => [
          'btn',
          'btn-primary',
          'btn-export-back',
        ],
      ],
    ],
  ];
  return $build;
}