You are here

function features_file_download in Features 8.4

Same name and namespace in other branches
  1. 8.3 features.module \features_file_download()

Implements hook_file_download().

File

./features.module, line 28
Main hooks for Features module.

Code

function features_file_download($uri) {
  $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
  $scheme = $stream_wrapper_manager
    ->getScheme($uri);
  $target = $stream_wrapper_manager
    ->getTarget($uri);
  if ($scheme == 'temporary' && $target) {
    $request = \Drupal::request();
    $route = $request->attributes
      ->get('_route');

    // Check if we were called by Features download route.
    // No additional access checking needed here: route requires
    // "export configuration" permission, token is validated by the controller.
    // @see \Drupal\features\Controller\FeaturesController::downloadExport()
    if ($route == 'features.export_download') {
      return [
        'Content-disposition' => 'attachment; filename="' . $target . '"',
      ];
    }
  }
}