From 7f45af486856bb9c5fba0bc4ee859c79cab02a56 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Fri, 4 Oct 2013 19:59:43 +0100
Subject: [PATCH] Issue #1829170 by LinL, socketwench, vijaycs85, mtift,
 LittleCoding, andypost, dawehner, ianmthomasuk: Convert the Maintenance Theme
 variable to settings.

---
 core/includes/theme.maintenance.inc | 30 ++++++++++++++---------------
 sites/default/default.settings.php  | 21 ++++++++++----------
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc
index 1f06a06719c6..b86a25dfa692 100644
--- a/core/includes/theme.maintenance.inc
+++ b/core/includes/theme.maintenance.inc
@@ -34,7 +34,7 @@ function _drupal_maintenance_theme() {
 
   // Install and update pages are treated differently to prevent theming overrides.
   if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
-    $custom_theme = (isset($conf['maintenance_theme']) ? $conf['maintenance_theme'] : 'seven');
+    $custom_theme = settings()->get('maintenance_theme', 'seven');
   }
   else {
     // The bootstrap was not complete. So we are operating in a crippled
@@ -44,23 +44,23 @@ function _drupal_maintenance_theme() {
       require_once __DIR__ . '/database.inc';
     }
 
-    // We use the default theme as the maintenance theme. If a default theme
-    // isn't specified in the database or in settings.php, we use Bartik.
-    // @todo Should use the actual default theme configured, but that depends on
-    //   configuration being available while possibly not having a working
-    //   database connection (yet). And only if that fails, should fall back to
-    //   Stark otherwise. Since there is no low-level access to configuration
-    //   currently, we only consult settings.php and fall back to Bartik
-    //   otherwise, as it looks generic enough and way more user-friendly.
-    $custom_theme = variable_get('maintenance_theme');
-    if (!$custom_theme)  {
-      $config = \Drupal::config('system.theme');
-      // A broken install might not return an object.
-      if (is_object($config)) {
+    // Use the maintenance theme if specified, otherwise attempt to use the
+    // default site theme.
+    try {
+      $custom_theme = settings()->get('maintenance_theme', '');
+      if (!$custom_theme) {
+        $config = \Drupal::config('system.theme');
         $custom_theme = $config->get('default');
       }
     }
-    if (!$custom_theme)  {
+    catch (\Exception $e) {
+      // Whatever went wrong (often a database connection problem), we are
+      // about to fall back to a sensible theme so there is no need for special
+      // handling.
+    }
+    if (!$custom_theme) {
+      // We have been unable to identify the configured theme, so fall back to
+      // a safe default. Bartik is reasonably user friendly and fairly generic.
       $custom_theme = 'bartik';
     }
   }
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index a58d60ef2d93..31c747d3db6e 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -472,6 +472,17 @@
  */
 # $settings['session_write_interval'] = 180;
 
+/**
+ * A custom theme for the offline page:
+ *
+ * This applies when the site is explicitly set to maintenance mode through the
+ * administration page or when the database is inactive due to an error.
+ * The template file should also be copied into the theme. It is located inside
+ * 'core/modules/system/maintenance-page.tpl.php'.
+ * Note: This setting does not apply to installation and update pages.
+ */
+# $settings['maintenance_theme'] = 'bartik';
+
 /**
  * Base URL (optional).
  *
@@ -573,16 +584,6 @@
 # $conf['system.theme']['default'] = 'stark';
 # $conf['anonymous'] = 'Visitor';
 
-/**
- * A custom theme can be set for the offline page. This applies when the site
- * is explicitly set to maintenance mode through the administration page or when
- * the database is inactive due to an error. It can be set through the
- * 'maintenance_theme' key. The template file should also be copied into the
- * theme. It is located inside 'core/modules/system/maintenance-page.tpl.php'.
- * Note: This setting does not apply to installation and update pages.
- */
-# $conf['maintenance_theme'] = 'bartik';
-
 /**
  * CSS/JS aggregated file gzip compression:
  *
-- 
GitLab