Drupal investigation

config.module 4.7KB

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