function content_file_download in Content Synchronization 8
Same name and namespace in other branches
- 8.2 content_sync.module \content_file_download()
- 3.0.x content_sync.module \content_file_download()
Implements hook_file_download().
File
- ./
content_sync.module, line 130 - Allows site administrators to modify content.
Code
function content_file_download($uri) {
$scheme = file_uri_scheme($uri);
$target = file_uri_target($uri);
if ($scheme == 'temporary' && $target == 'content.tar.gz') {
if (\Drupal::currentUser()
->hasPermission('export content')) {
$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 = 'content' . '-' . $hostname . '-' . $date_string . '.tar.gz';
$disposition = 'attachment; filename="' . $filename . '"';
return [
'Content-disposition' => $disposition,
];
}
return -1;
}
}