You are here

public function YamlFormResultsExportController::file in YAML Form 8

Returns form submission results as CSV file.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

string $filename: CSV file name.

Return value

array|\Symfony\Component\HttpFoundation\Response A response that renders or redirects to the CSV file.

2 string references to 'YamlFormResultsExportController::file'
yamlform.routing.yml in ./yamlform.routing.yml
yamlform.routing.yml
yamlform_node.routing.yml in modules/yamlform_node/yamlform_node.routing.yml
modules/yamlform_node/yamlform_node.routing.yml

File

src/Controller/YamlFormResultsExportController.php, line 150

Class

YamlFormResultsExportController
Controller routines for form submission export.

Namespace

Drupal\yamlform\Controller

Code

public function file(Request $request, $filename) {
  list($yamlform, $source_entity) = $this->requestHandler
    ->getYamlFormEntities();
  $this->submissionExporter
    ->setYamlForm($yamlform);
  $this->submissionExporter
    ->setSourceEntity($source_entity);
  $file_path = $this->submissionExporter
    ->getFileTempDirectory() . '/' . $filename;
  if (!file_exists($file_path)) {
    $route_name = $this->requestHandler
      ->getRouteName($yamlform, $source_entity, 'yamlform.results_export');
    $route_parameters = $this->requestHandler
      ->getRouteParameters($yamlform, $source_entity);
    $t_args = [
      ':href' => Url::fromRoute($route_name, $route_parameters)
        ->toString(),
    ];
    $build = [
      '#markup' => $this
        ->t('No export file ready for download. The file may have already been downloaded by your browser. Visit the <a href=":href">download export form</a> to create a new export.', $t_args),
    ];
    return $build;
  }
  else {
    return $this
      ->downloadFile($file_path);
  }
}