config.module 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @file
  4. * Allows site administrators to modify configuration.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\StreamWrapper\StreamWrapperManager;
  8. use Drupal\Core\Url;
  9. /**
  10. * Implements hook_help().
  11. */
  12. function config_help($route_name, RouteMatchInterface $route_match) {
  13. switch ($route_name) {
  14. case 'help.page.config':
  15. $output = '';
  16. $output .= '<h3>' . t('About') . '</h3>';
  17. $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>';
  18. $output .= '<h3>' . t('Uses') . '</h3>';
  19. $output .= '<dl>';
  20. $output .= '<dt>' . t('Exporting the full configuration') . '</dt>';
  21. $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>';
  22. $output .= '<dt>' . t('Importing a full configuration') . '</dt>';
  23. $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>';
  24. $output .= '<dt>' . t('Synchronizing configuration') . '</dt>';
  25. $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>';
  26. $output .= '<dt>' . t('Exporting a single configuration item') . '</dt>';
  27. $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>';
  28. $output .= '<dt>' . t('Importing a single configuration item') . '</dt>';
  29. $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>';
  30. $output .= '</dl>';
  31. return $output;
  32. case 'config.sync':
  33. $output = '';
  34. $output .= '<p>' . t('Compare the configuration uploaded to your sync directory with the active configuration before completing the import.') . '</p>';
  35. return $output;
  36. case 'config.export_full':
  37. $output = '';
  38. $output .= '<p>' . t('Export and download the full configuration of this site as a gzipped tar file.') . '</p>';
  39. return $output;
  40. case 'config.import_full':
  41. $output = '';
  42. $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>';
  43. return $output;
  44. case 'config.export_single':
  45. $output = '';
  46. $output .= '<p>' . t('Choose a configuration item to display its YAML structure.') . '</p>';
  47. return $output;
  48. case 'config.import_single':
  49. $output = '';
  50. $output .= '<p>' . t('Import a single configuration item by pasting its YAML structure into the text field.') . '</p>';
  51. return $output;
  52. }
  53. }
  54. /**
  55. * Implements hook_file_download().
  56. */
  57. function config_file_download($uri) {
  58. $scheme = StreamWrapperManager::getScheme($uri);
  59. $target = StreamWrapperManager::getTarget($uri);
  60. if ($scheme == 'temporary' && $target == 'config.tar.gz') {
  61. if (\Drupal::currentUser()->hasPermission('export configuration')) {
  62. $request = \Drupal::request();
  63. $date = DateTime::createFromFormat('U', $request->server->get('REQUEST_TIME'));
  64. $date_string = $date->format('Y-m-d-H-i');
  65. $hostname = str_replace('.', '-', $request->getHttpHost());
  66. $filename = 'config-' . $hostname . '-' . $date_string . '.tar.gz';
  67. $disposition = 'attachment; filename="' . $filename . '"';
  68. return [
  69. 'Content-disposition' => $disposition,
  70. ];
  71. }
  72. return -1;
  73. }
  74. }