function config_file_download in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config/config.module \config_file_download()
- 10 core/modules/config/config.module \config_file_download()
Implements hook_file_download().
File
- core/
modules/ config/ config.module, line 66 - Allows site administrators to modify configuration.
Code
function config_file_download($uri) {
$scheme = StreamWrapperManager::getScheme($uri);
$target = StreamWrapperManager::getTarget($uri);
if ($scheme == 'temporary' && $target == 'config.tar.gz') {
if (\Drupal::currentUser()
->hasPermission('export configuration')) {
$request = \Drupal::request();
$date = DateTime::createFromFormat('U', $request->server
->get('REQUEST_TIME'));
$date_string = $date
->format('Y-m-d-H-i');
$hostname = str_replace('.', '-', $request
->getHttpHost());
$filename = 'config-' . $hostname . '-' . $date_string . '.tar.gz';
$disposition = 'attachment; filename="' . $filename . '"';
return [
'Content-disposition' => $disposition,
];
}
return -1;
}
}