Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Allows site administrators to modify configuration.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@18
|
8 use Drupal\Core\Url;
|
Chris@0
|
9 use Drupal\Core\Routing\RouteMatchInterface;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Implements hook_help().
|
Chris@0
|
13 */
|
Chris@0
|
14 function config_help($route_name, RouteMatchInterface $route_match) {
|
Chris@0
|
15 switch ($route_name) {
|
Chris@0
|
16 case 'help.page.config':
|
Chris@0
|
17 $output = '';
|
Chris@0
|
18 $output .= '<h3>' . t('About') . '</h3>';
|
Chris@0
|
19 $output .= '<p>' . t('The Configuration Manager module provides a user interface for importing and exporting configuration changes between installations of your website in different environments. Configuration is stored in YAML format. For more information, see the <a href=":url">online documentation for the Configuration Manager module</a>.', [':url' => 'https://www.drupal.org/documentation/administer/config']) . '</p>';
|
Chris@0
|
20 $output .= '<h3>' . t('Uses') . '</h3>';
|
Chris@0
|
21 $output .= '<dl>';
|
Chris@0
|
22 $output .= '<dt>' . t('Exporting the full configuration') . '</dt>';
|
Chris@18
|
23 $output .= '<dd>' . t('You can create and download an archive consisting of all your site\'s configuration exported as <em>*.yml</em> files on the <a href=":url">Export</a> page.', [':url' => Url::fromRoute('config.export_full')->toString()]) . '</dd>';
|
Chris@0
|
24 $output .= '<dt>' . t('Importing a full configuration') . '</dt>';
|
Chris@18
|
25 $output .= '<dd>' . t('You can upload a full site configuration from an archive file on the <a href=":url">Import</a> page. When importing data from a different environment, the site and import files must have matching configuration values for UUID in the <em>system.site</em> configuration item. That means that your other environments should initially be set up as clones of the target site. Migrations are not supported.', [':url' => Url::fromRoute('config.import_full')->toString()]) . '</dd>';
|
Chris@0
|
26 $output .= '<dt>' . t('Synchronizing configuration') . '</dt>';
|
Chris@18
|
27 $output .= '<dd>' . t('You can review differences between the active configuration and an imported configuration archive on the <a href=":synchronize">Synchronize</a> page to ensure that the changes are as expected, before finalizing the import. The Synchronize page also shows configuration items that would be added or removed.', [':synchronize' => Url::fromRoute('config.sync')->toString()]) . '</dd>';
|
Chris@0
|
28 $output .= '<dt>' . t('Exporting a single configuration item') . '</dt>';
|
Chris@18
|
29 $output .= '<dd>' . t('You can export a single configuration item by selecting a <em>Configuration type</em> and <em>Configuration name</em> on the <a href=":single-export">Single export</a> page. The configuration and its corresponding <em>*.yml file name</em> are then displayed on the page for you to copy.', [':single-export' => Url::fromRoute('config.export_single')->toString()]) . '</dd>';
|
Chris@0
|
30 $output .= '<dt>' . t('Importing a single configuration item') . '</dt>';
|
Chris@18
|
31 $output .= '<dd>' . t('You can import a single configuration item by pasting it in YAML format into the form on the <a href=":single-import">Single import</a> page.', [':single-import' => Url::fromRoute('config.import_single')->toString()]) . '</dd>';
|
Chris@0
|
32 $output .= '</dl>';
|
Chris@0
|
33 return $output;
|
Chris@0
|
34
|
Chris@0
|
35 case 'config.sync':
|
Chris@0
|
36 $output = '';
|
Chris@0
|
37 $output .= '<p>' . t('Compare the configuration uploaded to your sync directory with the active configuration before completing the import.') . '</p>';
|
Chris@0
|
38 return $output;
|
Chris@0
|
39
|
Chris@0
|
40 case 'config.export_full':
|
Chris@0
|
41 $output = '';
|
Chris@0
|
42 $output .= '<p>' . t('Export and download the full configuration of this site as a gzipped tar file.') . '</p>';
|
Chris@0
|
43 return $output;
|
Chris@0
|
44
|
Chris@0
|
45 case 'config.import_full':
|
Chris@0
|
46 $output = '';
|
Chris@0
|
47 $output .= '<p>' . t('Upload a full site configuration archive to the sync directory. It can then be compared and imported on the Synchronize page.') . '</p>';
|
Chris@0
|
48 return $output;
|
Chris@0
|
49
|
Chris@0
|
50 case 'config.export_single':
|
Chris@0
|
51 $output = '';
|
Chris@0
|
52 $output .= '<p>' . t('Choose a configuration item to display its YAML structure.') . '</p>';
|
Chris@0
|
53 return $output;
|
Chris@0
|
54
|
Chris@0
|
55 case 'config.import_single':
|
Chris@0
|
56 $output = '';
|
Chris@0
|
57 $output .= '<p>' . t('Import a single configuration item by pasting its YAML structure into the text field.') . '</p>';
|
Chris@0
|
58 return $output;
|
Chris@0
|
59 }
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * Implements hook_file_download().
|
Chris@0
|
64 */
|
Chris@0
|
65 function config_file_download($uri) {
|
Chris@0
|
66 $scheme = file_uri_scheme($uri);
|
Chris@0
|
67 $target = file_uri_target($uri);
|
Chris@0
|
68 if ($scheme == 'temporary' && $target == 'config.tar.gz') {
|
Chris@0
|
69 if (\Drupal::currentUser()->hasPermission('export configuration')) {
|
Chris@0
|
70 $request = \Drupal::request();
|
Chris@0
|
71 $date = DateTime::createFromFormat('U', $request->server->get('REQUEST_TIME'));
|
Chris@0
|
72 $date_string = $date->format('Y-m-d-H-i');
|
Chris@0
|
73 $hostname = str_replace('.', '-', $request->getHttpHost());
|
Chris@18
|
74 $filename = 'config-' . $hostname . '-' . $date_string . '.tar.gz';
|
Chris@0
|
75 $disposition = 'attachment; filename="' . $filename . '"';
|
Chris@0
|
76 return [
|
Chris@0
|
77 'Content-disposition' => $disposition,
|
Chris@0
|
78 ];
|
Chris@0
|
79 }
|
Chris@0
|
80 return -1;
|
Chris@0
|
81 }
|
Chris@0
|
82 }
|