Problem/Motivation

Duplicate maintenance mode message displayed.

Steps to reproduce

  1. On any content type that has a simple file field, create a node with an attachment file.
  2. Put the site in maintenance mode.
  3. Edit the node and remove the file attachment by clicking on the "Remove" button beside the file.
  4. Now when the file is removed, the form has the "Operating in maintenance mode. Go Online" message at 2 more places on the form, apart from the usual top message.

Proposed resolution

Display on one message, at the top of the screen.

Remaining tasks

Write a test
Add new before screenshot to the User interface changes section of the Issue Summary
Add an after screenshot to the User interface changes section of the Issue Summary
Review

User interface changes

Before

After
after

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

CommentFileSizeAuthor
#56 2724829.55_56.interdiff.txt892 bytesdww
#56 2724829-56.patch4.18 KBdww
#55 2724829-55.patch4.18 KBsmustgrave
#55 interdiff-51-55.txt828 bytessmustgrave
#53 after-patch-2724829.jpg616.41 KBTanuj.
#53 before-patch-2724829.jpg664.64 KBTanuj.
#51 2724829-51.patch4.32 KBsmustgrave
#51 2724829-51-tests-only.patch2.14 KBsmustgrave
#51 interdiff-43-51.txt2.77 KBsmustgrave
#48 2724829-after_patch.jpg70.17 KBgaurav-mathur
#48 2724829-before_patch.jpg72.45 KBgaurav-mathur
#44 After Patch.png75.03 KBprasanth_kp
#44 Before Patch.png74.8 KBprasanth_kp
#43 2724829-43.patch5.47 KBsmustgrave
#43 interdiff-41-43.patch742 bytessmustgrave
#41 2724829-41.patch5.47 KBsmustgrave
#41 interdiff-38-41.txt6.18 KBsmustgrave
#38 2724829-38.patch5.44 KBsmustgrave
#38 interdiff-37-38.txt4.43 KBsmustgrave
#37 2724829-37.patch3.82 KBsmustgrave
#37 interdiff-24-37.txt1.52 KBsmustgrave
#34 2724829-34.patch4.23 KBsmustgrave
#34 interdiff-24-34.txt2.05 KBsmustgrave
#32 After patch #24.png537.15 KBnikhilraut
#32 Before patch #24.png539.93 KBnikhilraut
#30 After-Patch-2724829-24.png154.32 KBManibharathi E R
#30 Before-Patch-2724829-24.png304.56 KBManibharathi E R
#29 Screen Shot 2022-08-24 at 7.12.20 PM.png433.56 KBsmustgrave
#26 after.png73.48 KBMunavijayalakshmi
#26 before.png56.36 KBMunavijayalakshmi
#25 add_new_file.png71.21 KBMunavijayalakshmi
#24 2724829-24.patch3.66 KBsmustgrave
#24 interdiff-18-24.txt1.22 KBsmustgrave
#22 After Patch #18.png162.77 KByashingole
#22 Before Patch #18.png184.46 KByashingole
#18 2724829-18.patch3.51 KBsmustgrave
#18 interdiff-6-18.txt4.72 KBsmustgrave
#18 2724829-18-tests-only.patch1.64 KBsmustgrave
#6 2724829-06.patch1.86 KBaneek
#5 configuration_single_export.png19.13 KBaneek
#4 managed file.png952.86 KBscythian
Drupal Bug.png84.82 KBsaitanay
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

saitanay created an issue. See original summary.

saitanay’s picture

Issue summary: View changes
scythian’s picture

Assigned: Unassigned » scythian
scythian’s picture

Assigned: scythian » Unassigned
FileSize
952.86 KB

Error is related to element rendering. By some reason AJAX wrapper with same ID applied twice http://take.ms/tux7C, also validation callback triggered twice too.

aneek’s picture

Version: 8.1.1 » 8.1.x-dev
Component: forms system » base system
Assigned: Unassigned » aneek
Issue summary: View changes
Issue tags: +maintenance mode
FileSize
19.13 KB

This same issue can be observed while in the configuration export (single) page.

Screenshot:

aneek’s picture

Uploading a new patch which fixes this in the \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber

aneek’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: 2724829-06.patch, failed testing.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.9.x-dev » 9.4.x-dev
Assigned: aneek » Unassigned
Issue summary: View changes
Issue tags: +Bug Smash Initiative, +Needs tests

@aneek, thanks for the report and the patch.

I tested this on Drupal 4.x and confirmed the problem still exists. In order to test the patch I rerolled it. I'm attaching the patch but not running tests because this also needs a test. Adding a tag for the test.

Updated the IS. Un-assigning because it has been more than 5 years since this was working ed.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.64 KB
4.72 KB
3.51 KB

Status: Needs review » Needs work

The last submitted patch, 18: 2724829-18.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review

Moving back to NR. Test fails were caused by broken dev branch.

yashingole’s picture

Assigned: Unassigned » yashingole
yashingole’s picture

Assigned: yashingole » Unassigned
Status: Needs review » Reviewed & tested by the community
FileSize
184.46 KB
162.77 KB

Verified and tested patch #18 on Drupal 9.5.x-dev. Patch applied successfully and looks good to me.
Testing steps:
1. Add Content Article type.
2. Add an image.
3. Save the page.
4. Put the site in maintenance mode.
5. Edit the node and remove the file attachment by clicking on the "Remove" button beside the file.
6. Observe that the "Operating in maintenance mode. Go online." message appears twice at the top and in the image section.
Testing Result:
1. After applying the patch the "Operating in maintenance mode. Go online." message appears at the top only.
Can be move to RTBC

quietone’s picture

Status: Reviewed & tested by the community » Needs work

@yashingole, thanks for the manual testing! It would help if you added the screens shots to the issue summary.

The remaining tasks in the issue summary need to be updated.

What I don't see here is any review of the code changes. My comment below is not a full review of the code.

+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
@@ -128,14 +128,17 @@ public function onKernelRequestMaintenance(RequestEvent $event) {
+        // maintenance mode.
+        // But don't show maintenance message while an AJAX or Iframe upload.
+        // However, suppress it on the maintenance mode settings page.

This is not wrapped at 80 columns

smustgrave’s picture

Status: Needs work » Needs review
FileSize
1.22 KB
3.66 KB

Fixed the wrapping text. Not sure what needs to be updated in the IS though? It's got clear steps and screenshot.

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
Status: Needs review » Needs work
FileSize
71.21 KB

ignore please

Munavijayalakshmi’s picture

FileSize
56.36 KB
73.48 KB

#24 patch working fine.

Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned
Status: Needs work » Reviewed & tested by the community
quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -maintenance mode +Needs issue summary update

Reviewing RTBC issues to check they pass the core gates.

An issue summary update was asked for in #23, that has not happened, adding tag. There is no evidence of a code review here.

There are several steps, or gates, that an issue must pass before it is marked RTBC. For most issues following step 10 in the Review a patch or merge request task of the Contributor guide is sufficient. The complete list of core gates has more topics. Also, check the tags on the issue and make sure they are complete.

Therefor, credit has been removed per How is credit granted for Drupal core issues. And remember to read the issue summary and the comments before working on issue.

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
FileSize
433.56 KB
Manibharathi E R’s picture

Patch #24 tested and Applied successfully on Drupal 9.5.x.

Before patch:
Before-Patch

After Patch:
After-patch

nikhilraut’s picture

Assigned: Unassigned » nikhilraut
nikhilraut’s picture

Assigned: nikhilraut » Unassigned
Status: Needs review » Reviewed & tested by the community
FileSize
539.93 KB
537.15 KB

Patch #24 working fine on drupal 9.5

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. We shouldn't be putting this test coverage in the file module we should be putting this in the System module.
  2. +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
    @@ -127,15 +127,18 @@ public function onKernelRequestMaintenance(RequestEvent $event) {
             if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
    -          if ($this->account->hasPermission('administer site configuration')) {
    -            $this->messenger->addMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
    -          }
    -          else {
    -            $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
    +          if (!$event->getRequest()->isXmlHttpRequest() && $event->getRequest()->get('ajax_iframe_upload', FALSE) === FALSE) {
    +            if ($this->account->hasPermission('administer site configuration')) {
    +              $this->messenger->addMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
    +            }
    +            else {
    +              $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
    +            }
               }
             }
    

    Let's change this to:

            $show_message = $route_match->getRouteName() != 'system.site_maintenance_mode' &&
              !$event->getRequest()->isXmlHttpRequest() && 
              $event->getRequest()->get('ajax_iframe_upload', FALSE) === FALSE;
            
            if ($show_message) {
              if ($this->account->hasPermission('administer site configuration')) {
                $this->messenger->addMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
              }
              else {
                $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
              }
            }
    

    It's a bit more readable and less levels of ifs.

  3. Also the comment is not that readable now... let's change
            // Display a message if the logged-in user has access to the site in
            // maintenance mode. But don't show maintenance message while an AJAX
            // or Iframe upload. However, suppress it on the maintenance mode
            // settings page.
    

    to

            // Display a message if the logged-in user has access to the site in
            // maintenance mode. Don't show maintenance message:
            // - on AJAX requests.
            // - on Iframe uploads.
            // - on the maintenance mode settings page.
    
smustgrave’s picture

Status: Needs work » Needs review
FileSize
2.05 KB
4.23 KB

Addressed the points in #33

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
similarity index 95%
rename from core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php

rename from core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php
rename to core/modules/system/tests/src/FunctionalJavascript/File/FileFieldWidgetTest.php

The rest of this test is file test... I'm not sure that using the file field to test this is correct... but even so the rest of the test should stay in the file module. There are a number of modules in system test modules that provide ajax routes.

alexpott’s picture

See the ajax_test module for example and \Drupal\FunctionalJavascriptTests\Ajax\MessageCommandTest::testMessageCommand

smustgrave’s picture

Went back to the original patch in #24

Addressed 2 and 3 in #33

For #1 could this remain in the file module? The test was written to tie into an existing test.

smustgrave’s picture

FileSize
4.43 KB
5.44 KB

Moved test

Status: Needs review » Needs work

The last submitted patch, 38: 2724829-38.patch, failed testing. View results

alexpott’s picture

  1. +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/FileWidgetTest.php
    @@ -0,0 +1,96 @@
    +class FileWidgetTest extends WebDriverTestBase {
    

    We're not testing the file widget we're testing the maintenance mode with AjAX requests.

  2. +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/FileWidgetTest.php
    @@ -0,0 +1,96 @@
    +  protected static $modules = ['node', 'file', 'file_module_test', 'field_ui'];
    

    I think we should change the test to use the ajax_test module.

smustgrave’s picture

Status: Needs work » Needs review
FileSize
6.18 KB
5.47 KB

Updated the tests to be more accurate.

Tried updating to ajax_test but all those URLs are not accessible when logged in. Could not figure that out.

Status: Needs review » Needs work

The last submitted patch, 41: 2724829-41.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
FileSize
742 bytes
5.47 KB

Wrong namespace

prasanth_kp’s picture

FileSize
74.8 KB
75.03 KB

Thanks for the patch 2724829-43.patch, Its working perfectly fine on 9.5.x-dev

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Rerunning for 10.1

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
FileSize
72.45 KB
70.17 KB

Hi i applied patch#43. it is work fine and looks good.

Steps of testing:-

1. Add image field on article content type.
2. Add content on using article.
3. Add an title and image or save the page.
4. Put the site in maintenance mode.
5. Edit the node and remove the file attachment by clicking on the Remove button beside the file.
6. Observe that the Operating in maintenance mode. Go online. message appears twice at the top and in the image section.

Result After Apply Patch:-

1. After applying the patch the Operating in maintenance mode. Go online. message appears at the top only.

Adding screenshot for the reference.
Thank You

jungle’s picture

+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
@@ -0,0 +1,96 @@
+class AjaxMaintenanceModeTest extends WebDriverTestBase {

Agree with @alexpott in #40,and the test could be simplified by using ajax_test, or ajax_form_test.

smustgrave’s picture

Status: Needs review » Needs work

Will give it another shot but was having issues with those test modules

Thanks!

smustgrave’s picture

Fixed up tests.

The last submitted patch, 51: 2724829-51-tests-only.patch, failed testing. View results

Tanuj.’s picture

Tested and verified patch #51 with drupal: 10.1.x and the patch applied successfully and fixed the issue of multiple message on page. adding screenshots for reference. RTBC+1

larowlan’s picture

+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
@@ -0,0 +1,72 @@
+    // Turn on maintenance mode.
+    $edit = [
+      'maintenance_mode' => 1,
+    ];
+    $this->drupalGet('admin/config/development/maintenance');
+    $this->submitForm($edit, 'Save configuration');

Micro-optimisation, but I think we can enable this by setting the flag direct in state rather than needing to submit the form, will save a few HTTP requests and speed up the test

Other than that, makes sense to me

smustgrave’s picture

dww’s picture

The test-only patch is failing exactly as expected:

1) Drupal\FunctionalJavascriptTests\Ajax\AjaxMaintenanceModeTest::testAjaxCallMaintenanceMode
Behat\Mink\Exception\ResponseTextException: Failed asserting that the page matches the pattern '/Operating in maintenance mode/ui' 1 time(s), 2 found.
Failed asserting that 2 is identical to 1.

I closely reviewed the code here. Almost all looked great. Found a couple of very trivial nits. Fixing those as a new patch and RTBC'ing.

dww’s picture

Status: Needs review » Reviewed & tested by the community

  • catch committed dbd61328 on 10.1.x
    Issue #2724829 by smustgrave, aneek, dww, saitanay, alexpott, quietone,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed dbd6132 and pushed to 10.1.x. Thanks!

alexpott’s picture

Version: 10.1.x-dev » 10.0.x-dev
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
index 4d4d72b8ad..335557cdba 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
@@ -18,13 +18,6 @@ class AjaxMaintenanceModeTest extends WebDriverTestBase {
   use FileFieldCreationTrait;
   use TestFileCreationTrait;
 
-  /**
-   * An user with administration permissions.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $adminUser;
-
   /**
    * {@inheritdoc}
    */
@@ -40,26 +33,22 @@ class AjaxMaintenanceModeTest extends WebDriverTestBase {
    */
   protected function setUp(): void {
     parent::setUp();
-    $this->adminUser = $this->drupalCreateUser([
+    $this->drupalLogin($this->drupalCreateUser([
       'access administration pages',
       'administer site configuration',
       'access site in maintenance mode',
-    ]);
-    $this->drupalLogin($this->adminUser);
+    ]));
   }
 
   /**
    * Tests maintenance message only appears once on an AJAX call.
    */
   public function testAjaxCallMaintenanceMode(): void {
-    $page = $this->getSession()->getPage();
-    $assert_session = $this->assertSession();
-
     \Drupal::state()->set('system.maintenance_mode', TRUE);
 
     $this->drupalGet('ajax-test/insert-inline-wrapper');
-    $assert_session->pageTextContains('Target inline');
-    $page->clickLink('Link html pre-wrapped-div');
+    $this->assertSession()->pageTextContains('Target inline');
+    $this->clickLink('Link html pre-wrapped-div');
     $this->assertSession()->assertWaitOnAjaxRequest();
     $this->assertSession()->pageTextContainsOnce('Operating in maintenance mode');
   }

I was going to make the above changes on commit. Not important enough to do a revert but maybe someone wants to do a followup. We don't need the adminUser variable on test object and the $page and $assert_session variables are unnecessary and not even used consistently.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.