Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Theming for maintenance pages.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Site\Settings;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Sets up the theming system for maintenance page.
|
Chris@0
|
12 *
|
Chris@0
|
13 * Used for site installs, updates and when the site is in maintenance mode.
|
Chris@0
|
14 * It also applies when the database is unavailable or bootstrap was not
|
Chris@0
|
15 * complete. Seven is always used for the initial install and update
|
Chris@0
|
16 * operations. In other cases, Bartik is used, but this can be overridden by
|
Chris@0
|
17 * setting a "maintenance_theme" key in the $settings variable in settings.php.
|
Chris@0
|
18 */
|
Chris@0
|
19 function _drupal_maintenance_theme() {
|
Chris@0
|
20 // If the theme is already set, assume the others are set too, and do nothing.
|
Chris@0
|
21 if (\Drupal::theme()->hasActiveTheme()) {
|
Chris@0
|
22 return;
|
Chris@0
|
23 }
|
Chris@0
|
24
|
Chris@0
|
25 require_once __DIR__ . '/theme.inc';
|
Chris@0
|
26 require_once __DIR__ . '/common.inc';
|
Chris@0
|
27 require_once __DIR__ . '/unicode.inc';
|
Chris@0
|
28 require_once __DIR__ . '/file.inc';
|
Chris@0
|
29 require_once __DIR__ . '/module.inc';
|
Chris@0
|
30 require_once __DIR__ . '/database.inc';
|
Chris@0
|
31
|
Chris@0
|
32 // Install and update pages are treated differently to prevent theming overrides.
|
Chris@0
|
33 if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
|
Chris@0
|
34 if (drupal_installation_attempted()) {
|
Chris@0
|
35 $custom_theme = $GLOBALS['install_state']['theme'];
|
Chris@0
|
36 }
|
Chris@0
|
37 else {
|
Chris@0
|
38 $custom_theme = Settings::get('maintenance_theme', 'seven');
|
Chris@0
|
39 }
|
Chris@0
|
40 }
|
Chris@0
|
41 else {
|
Chris@0
|
42 // Use the maintenance theme if specified, otherwise attempt to use the
|
Chris@0
|
43 // default site theme.
|
Chris@0
|
44 try {
|
Chris@0
|
45 $custom_theme = Settings::get('maintenance_theme', '');
|
Chris@0
|
46 if (!$custom_theme) {
|
Chris@0
|
47 $config = \Drupal::config('system.theme');
|
Chris@0
|
48 $custom_theme = $config->get('default');
|
Chris@0
|
49 }
|
Chris@0
|
50 }
|
Chris@0
|
51 catch (\Exception $e) {
|
Chris@0
|
52 // Whatever went wrong (often a database connection problem), we are
|
Chris@0
|
53 // about to fall back to a sensible theme so there is no need for special
|
Chris@0
|
54 // handling.
|
Chris@0
|
55 }
|
Chris@0
|
56 if (!$custom_theme) {
|
Chris@0
|
57 // We have been unable to identify the configured theme, so fall back to
|
Chris@0
|
58 // a safe default. Bartik is reasonably user friendly and fairly generic.
|
Chris@0
|
59 $custom_theme = 'bartik';
|
Chris@0
|
60 }
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 $themes = \Drupal::service('theme_handler')->listInfo();
|
Chris@0
|
64
|
Chris@0
|
65 // If no themes are installed yet, or if the requested custom theme is not
|
Chris@0
|
66 // installed, retrieve all available themes.
|
Chris@0
|
67 /** @var \Drupal\Core\Theme\ThemeInitialization $theme_init */
|
Chris@0
|
68 $theme_init = \Drupal::service('theme.initialization');
|
Chris@0
|
69 $theme_handler = \Drupal::service('theme_handler');
|
Chris@0
|
70 if (empty($themes) || !isset($themes[$custom_theme])) {
|
Chris@18
|
71 $themes = \Drupal::service('extension.list.theme')->getList();
|
Chris@0
|
72 $theme_handler->addTheme($themes[$custom_theme]);
|
Chris@0
|
73 }
|
Chris@0
|
74
|
Chris@0
|
75 // \Drupal\Core\Extension\ThemeHandlerInterface::listInfo() triggers a
|
Chris@0
|
76 // \Drupal\Core\Extension\ModuleHandler::alter() in maintenance mode, but we
|
Chris@0
|
77 // can't let themes alter the .info.yml data until we know a theme's base
|
Chris@0
|
78 // themes. So don't set active theme until after
|
Chris@0
|
79 // \Drupal\Core\Extension\ThemeHandlerInterface::listInfo() builds its cache.
|
Chris@0
|
80 $theme = $custom_theme;
|
Chris@0
|
81
|
Chris@0
|
82 // Find all our ancestor themes and put them in an array.
|
Chris@0
|
83 // @todo This is just a workaround. Find a better way how to handle themes
|
Chris@0
|
84 // on maintenance pages, see https://www.drupal.org/node/2322619.
|
Chris@0
|
85 // This code is basically a duplicate of
|
Chris@0
|
86 // \Drupal\Core\Theme\ThemeInitialization::getActiveThemeByName.
|
Chris@0
|
87 $base_themes = [];
|
Chris@0
|
88 $ancestor = $theme;
|
Chris@0
|
89 while ($ancestor && isset($themes[$ancestor]->base_theme)) {
|
Chris@0
|
90 $base_themes[] = $themes[$themes[$ancestor]->base_theme];
|
Chris@0
|
91 $ancestor = $themes[$ancestor]->base_theme;
|
Chris@0
|
92 if ($ancestor) {
|
Chris@0
|
93 // Ensure that the base theme is added and installed.
|
Chris@0
|
94 $theme_handler->addTheme($themes[$ancestor]);
|
Chris@0
|
95 }
|
Chris@0
|
96 }
|
Chris@0
|
97 \Drupal::theme()->setActiveTheme($theme_init->getActiveTheme($themes[$custom_theme], $base_themes));
|
Chris@0
|
98 // Prime the theme registry.
|
Chris@0
|
99 Drupal::service('theme.registry');
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * Prepares variables for authorize.php operation report templates.
|
Chris@0
|
104 *
|
Chris@0
|
105 * This report displays the results of an operation run via authorize.php.
|
Chris@0
|
106 *
|
Chris@0
|
107 * Default template: authorize-report.html.twig.
|
Chris@0
|
108 *
|
Chris@0
|
109 * @param array $variables
|
Chris@0
|
110 * An associative array containing:
|
Chris@0
|
111 * - messages: An array of result messages.
|
Chris@0
|
112 */
|
Chris@0
|
113 function template_preprocess_authorize_report(&$variables) {
|
Chris@0
|
114 $messages = [];
|
Chris@0
|
115 if (!empty($variables['messages'])) {
|
Chris@0
|
116 foreach ($variables['messages'] as $heading => $logs) {
|
Chris@0
|
117 $items = [];
|
Chris@0
|
118 foreach ($logs as $number => $log_message) {
|
Chris@0
|
119 if ($number === '#abort') {
|
Chris@0
|
120 continue;
|
Chris@0
|
121 }
|
Chris@0
|
122 $class = 'authorize-results__' . ($log_message['success'] ? 'success' : 'failure');
|
Chris@0
|
123 $items[] = [
|
Chris@0
|
124 '#wrapper_attributes' => ['class' => [$class]],
|
Chris@0
|
125 '#markup' => $log_message['message'],
|
Chris@0
|
126 ];
|
Chris@0
|
127 }
|
Chris@0
|
128 $messages[] = [
|
Chris@0
|
129 '#theme' => 'item_list',
|
Chris@0
|
130 '#items' => $items,
|
Chris@0
|
131 '#title' => $heading,
|
Chris@0
|
132 ];
|
Chris@0
|
133 }
|
Chris@0
|
134 }
|
Chris@0
|
135 $variables['messages'] = $messages;
|
Chris@0
|
136 }
|