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