-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_fixtures.module
More file actions
51 lines (46 loc) · 1.42 KB
/
data_fixtures.module
File metadata and controls
51 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* @file
* Contains data_fixtures.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*
* @param $route_name
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
*
* @return string
*/
function data_fixtures_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the data_fixtures module.
case 'help.page.data_fixtures':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('My Awesome Module') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_file_download().
*/
function data_fixtures_file_download($uri) {
$scheme = \Drupal::service('file_system')->uriScheme($uri);
$target = file_uri_target($uri);
if ($scheme == 'temporary' && $target === 'fixtures.tar.gz') {
if (\Drupal::currentUser()->hasPermission('export data fixtures')) {
$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 = 'fixtures' . '-' . $hostname . '-' . $date_string . '.tar.gz';
$disposition = 'attachment; filename="' . $filename . '"';
return [
'Content-disposition' => $disposition,
];
}
return -1;
}
}