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