public function ScanResultController::resultExport in Upgrade Status 8
Same name and namespace in other branches
- 8.3 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 $type: Type of the extension, it can be either 'module' or 'theme' or 'profile'.
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 96
Class
Namespace
Drupal\upgrade_status\ControllerCode
public function resultExport(string $type, string $project_machine_name, string $format) {
$extension = $this->projectCollector
->loadProject($type, $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'][empty($extension->info['project']) ? '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;
}