public function ScanResultController::resultExport in Upgrade Status 8.3
Same name and namespace in other branches
- 8 src/Controller/ScanResultController.php \Drupal\upgrade_status\Controller\ScanResultController::resultExport()
- 8.2 src/Controller/ScanResultController.php \Drupal\upgrade_status\Controller\ScanResultController::resultExport()
Generates single project export.
Parameters
string $project_machine_name: The machine name of the project.
string $format: The format to use when exporting the data: html or ascii.
Return value
\Symfony\Component\HttpFoundation\Response Response object.
1 string reference to 'ScanResultController::resultExport'
File
- src/
Controller/ ScanResultController.php, line 92
Class
Namespace
Drupal\upgrade_status\ControllerCode
public function resultExport(string $project_machine_name, string $format) {
$extension = $this->projectCollector
->loadProject($project_machine_name);
$result = $this->resultFormatter
->getRawResult($extension);
// Sanitize user input.
if (!in_array($format, [
'html',
'ascii',
])) {
$format = 'html';
}
$build = [
'#theme' => 'upgrade_status_' . $format . '_export',
];
$build['#projects'][$extension->info['upgrade_status_type'] == ProjectCollector::TYPE_CUSTOM ? 'custom' : 'contrib'] = [
$project_machine_name => $format == 'html' ? $this->resultFormatter
->formatResult($extension) : $this->resultFormatter
->formatAsciiResult($extension),
];
$fileDate = $this->resultFormatter
->formatDateTime($result['date'], 'html_datetime');
$extension = $format == 'html' ? '.html' : '.txt';
$filename = 'single-export-' . $project_machine_name . '-' . $fileDate . $extension;
$response = new Response($this->renderer
->renderRoot($build));
$response->headers
->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
}