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