function ConfigHooks::fileDownload

Implements hook_file_download().

File

core/modules/config/src/Hook/ConfigHooks.php, line 74

Class

ConfigHooks
Hook implementations for config.

Namespace

Drupal\config\Hook

Code

public function fileDownload($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;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.