diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
index 23a2daa..6d48a3e 100644
--- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
@@ -123,15 +123,23 @@ public function onKernelRequestMaintenance(RequestEvent $event) {
$this->eventDispatcher->dispatch($event, MaintenanceModeEvents::MAINTENANCE_MODE_REQUEST);
}
else {
- // Display a message if the logged in user has access to the site in
- // maintenance mode. However, suppress it on the maintenance mode
- // settings page.
+ // 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.
if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
- if ($this->account->hasPermission('administer site configuration')) {
- $this->messenger->addMessage($this->t('Operating in maintenance mode. Go online.', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
- }
- else {
- $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
+ $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. Go online.', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
+ }
+ else {
+ $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
+ }
}
}
}
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
new file mode 100644
index 0000000..4d4d72b
--- /dev/null
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxMaintenanceModeTest.php
@@ -0,0 +1,67 @@
+adminUser = $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()->assertWaitOnAjaxRequest();
+ $this->assertSession()->pageTextContainsOnce('Operating in maintenance mode');
+ }
+
+}