diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
index 2ae47c8..2c2f664 100644
--- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
@@ -11,13 +11,13 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Page\DefaultHtmlPageRenderer;
+use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\StatusNegotiatorInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
-use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
@@ -88,9 +88,9 @@ public function __construct(StatusNegotiatorInterface $status_negotiator, Config
* The event to process.
*/
public function onKernelRequestMaintenance(GetResponseEvent $event) {
- $request = $event->getRequest();
if ($this->statusNegotiator->getStatus() != StatusNegotiatorInterface::SITE_ONLINE) {
- if (!$this->statusNegotiator->exempt($request, $this->account)) {
+ $route_match = RouteMatch::createFromRequest($event->getRequest());
+ if (!$this->statusNegotiator->exempt($route_match, $this->account)) {
// Deliver the 503 page if the site is in maintenance mode and the
// logged in user is not allowed to bypass it.
drupal_maintenance_theme();
@@ -106,8 +106,7 @@ public function onKernelRequestMaintenance(GetResponseEvent $event) {
// Display a message if the logged in user has access to the site in
// maintenance mode. However, suppress it on the maintenance mode
// setting spage.
- $is_maintenance_route = $request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'system.site_maintenance_mode';
- if (!$is_maintenance_route) {
+ if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
if ($this->account->hasPermission('administer site configuration')) {
$this->drupalSetMessage($this->t('Operating in maintenance mode. Go online.', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
}
diff --git a/core/lib/Drupal/Core/Site/MaintenanceExemptionInterface.php b/core/lib/Drupal/Core/Site/MaintenanceExemptionInterface.php
index 506985f..01a487f 100644
--- a/core/lib/Drupal/Core/Site/MaintenanceExemptionInterface.php
+++ b/core/lib/Drupal/Core/Site/MaintenanceExemptionInterface.php
@@ -7,7 +7,7 @@
namespace Drupal\Core\Site;
use Drupal\Core\Session\AccountInterface;
-use Symfony\Component\HttpFoundation\Request;
+use Drupal\Core\Routing\RouteMatchInterface;
/**
* Provides an interface for maintenance mode exemption rule implementations.
@@ -17,17 +17,14 @@
/**
* Returns TRUE if the given account should be exempted from maintenance mode.
*
- * @todo Use RouteMatch instead of the Request, once it is available.
- * https://www.drupal.org/node/2238217
- *
- * @param \Symfony\Component\HttpFoundation\Request $request
- * The current request.
+ * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
+ * The current route match.
* @param \Drupal\Core\Session\AccountInterface $account
* The logged in user.
*
* @return bool
* TRUE if the user should be exempted from maintenance mode.
*/
- public function exempt(Request $request, AccountInterface $account);
+ public function exempt(RouteMatchInterface $route_match, AccountInterface $account);
}
diff --git a/core/lib/Drupal/Core/Site/StatusNegotiator.php b/core/lib/Drupal/Core/Site/StatusNegotiator.php
index 62abdc5..4e5be60 100644
--- a/core/lib/Drupal/Core/Site/StatusNegotiator.php
+++ b/core/lib/Drupal/Core/Site/StatusNegotiator.php
@@ -7,9 +7,9 @@
namespace Drupal\Core\Site;
-use Drupal\Core\State\StateInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
-use Symfony\Component\HttpFoundation\Request;
+use Drupal\Core\State\StateInterface;
/**
* Provides the default implementation of the site status negotiator.
@@ -51,9 +51,9 @@ public function getStatus() {
/**
* {@inheritdoc}
*/
- public function exempt(Request $request, AccountInterface $account) {
+ public function exempt(RouteMatchInterface $route_match, AccountInterface $account) {
foreach ($this->exemptionHandlers as $handler) {
- if ($handler->exempt($request, $account)) {
+ if ($handler->exempt($route_match, $account)) {
return TRUE;
}
}
diff --git a/core/modules/system/src/Site/MaintenanceExemption.php b/core/modules/system/src/Site/MaintenanceExemption.php
index 24a8b37..22036f5 100644
--- a/core/modules/system/src/Site/MaintenanceExemption.php
+++ b/core/modules/system/src/Site/MaintenanceExemption.php
@@ -7,9 +7,9 @@
namespace Drupal\system\Site;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\MaintenanceExemptionInterface;
-use Symfony\Component\HttpFoundation\Request;
/**
* Exempts administrators from the maintenance mode.
@@ -19,7 +19,7 @@ class MaintenanceExemption implements MaintenanceExemptionInterface {
/**
* {@inheritdoc}
*/
- public function exempt(Request $request, AccountInterface $account) {
+ public function exempt(RouteMatchInterface $route_match, AccountInterface $account) {
if ($account->hasPermission('access site in maintenance mode')) {
return TRUE;
}
diff --git a/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php b/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php
index ce4db76..73d5c9e 100644
--- a/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php
+++ b/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php
@@ -7,6 +7,7 @@
namespace Drupal\user\EventSubscriber;
+use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\StatusNegotiatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -57,8 +58,9 @@ public function onKernelRequestMaintenance(GetResponseEvent $event) {
$site_status = $this->statusNegotiator->getStatus();
$path = $request->attributes->get('_system_path');
if ($site_status == StatusNegotiatorInterface::SITE_OFFLINE) {
+ $route_match = RouteMatch::createFromRequest($request);
// If the site is offline, log out unprivileged users.
- if ($this->account->isAuthenticated() && !$this->statusNegotiator->exempt($request, $this->account)) {
+ if ($this->account->isAuthenticated() && !$this->statusNegotiator->exempt($route_match, $this->account)) {
user_logout();
// Redirect to homepage.
$event->setResponse(new RedirectResponse(url('', array('absolute' => TRUE))));
diff --git a/core/modules/user/src/Site/MaintenanceExemption.php b/core/modules/user/src/Site/MaintenanceExemption.php
index 05a3052..c914c4d 100644
--- a/core/modules/user/src/Site/MaintenanceExemption.php
+++ b/core/modules/user/src/Site/MaintenanceExemption.php
@@ -7,9 +7,9 @@
namespace Drupal\user\Site;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\MaintenanceExemptionInterface;
-use Symfony\Component\HttpFoundation\Request;
/**
* Exempts login and password-retrieval form from the maintenance mode.
@@ -19,9 +19,9 @@ class MaintenanceExemption implements MaintenanceExemptionInterface {
/**
* {@inheritdoc}
*/
- public function exempt(Request $request, AccountInterface $account) {
- $path = $request->attributes->get('_system_path');
- if ($path == 'user/login' || $path == 'user/password' || strpos($path, 'user/reset/') === 0) {
+ public function exempt(RouteMatchInterface $route_match, AccountInterface $account) {
+ $route_name = $route_match->getRouteName();
+ if ($route_name == 'user.login' || $route_name == 'user.pass' || $route_name == 'user.reset') {
return TRUE;
}
}