From f101c6e2fccba1177aaef6f8b20eff096d462b67 Mon Sep 17 00:00:00 2001
From: "Theresa.Grannum" <theresa.grannum@3688861.no-reply.drupal.org>
Date: Tue, 17 May 2022 20:19:25 +0000
Subject: [PATCH] Issue #3277817 by Theresa.Grannum, mherman-pro: Before
 applying the update, don't show the checkbox for maintenance mode if the site
 is already in maintenance mode

---
 src/Form/UpdateReady.php                 | 14 +++++++++-----
 tests/src/Functional/UpdaterFormTest.php |  7 ++++++-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php
index 5d872e729f..1a0d628a8d 100644
--- a/src/Form/UpdateReady.php
+++ b/src/Form/UpdateReady.php
@@ -165,11 +165,14 @@ class UpdateReady extends FormBase {
       '#markup' => $this->t('Back up your database and site before you continue. <a href=":backup_url">Learn how</a>.', [':backup_url' => 'https://www.drupal.org/node/22281']),
       '#suffix' => '</strong>',
     ];
-    $form['maintenance_mode'] = [
-      '#title' => $this->t('Perform updates with site in maintenance mode (strongly recommended)'),
-      '#type' => 'checkbox',
-      '#default_value' => TRUE,
-    ];
+    if (!$this->state->get('system.maintenance_mode')) {
+      $form['maintenance_mode'] = [
+        '#title' => $this->t('Perform updates with site in maintenance mode (strongly recommended)'),
+        '#type' => 'checkbox',
+        '#default_value' => TRUE,
+      ];
+    }
+
     $form['actions']['submit'] = [
       '#type' => 'submit',
       '#value' => $this->t('Continue'),
@@ -204,6 +207,7 @@ class UpdateReady extends FormBase {
     if ($form_state->getValue('maintenance_mode')) {
       $this->state->set('system.maintenance_mode', TRUE);
     }
+
     $stage_id = $form_state->getValue('stage_id');
     $batch = (new BatchBuilder())
       ->setTitle($this->t('Apply updates'))
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index 69ffa8a87d..cd1ec9b129 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -413,7 +413,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $possible_update_message = 'Possible database updates were detected in the following modules; you may be redirected to the database update page in order to complete the update process.';
     $assert_session->pageTextContains($possible_update_message);
     $assert_session->pageTextContains('System');
-    $assert_session->checkboxChecked('maintenance_mode');
+    if ($maintenance_mode_on === TRUE) {
+      $assert_session->fieldNotExists('maintenance_mode');
+    }
+    else {
+      $assert_session->checkboxChecked('maintenance_mode');
+    }
     $assert_session->pageTextNotContains($cached_message);
     $page->pressButton('Continue');
     $this->checkForMetaRefresh();
-- 
GitLab