diff --git a/core/modules/system/src/Form/SiteMaintenanceModeForm.php b/core/modules/system/src/Form/SiteMaintenanceModeForm.php
index 02c5a9a3a2c10c70a42e386bab180c4cf1e0cefe..0d0b2afe0ce58c68b8dda229adfee1d29313c849 100644
--- a/core/modules/system/src/Form/SiteMaintenanceModeForm.php
+++ b/core/modules/system/src/Form/SiteMaintenanceModeForm.php
@@ -6,6 +6,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Form\ConfigFormBase;
+use Drupal\user\PermissionHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -20,6 +21,13 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
*/
protected $state;
+ /**
+ * The permission handler.
+ *
+ * @var \Drupal\user\PermissionHandlerInterface
+ */
+ protected $permissionHandler;
+
/**
* Constructs a new SiteMaintenanceModeForm.
*
@@ -27,10 +35,13 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
* The factory for configuration objects.
* @param \Drupal\Core\State\StateInterface $state
* The state keyvalue collection to use.
+ * @param \Drupal\user\PermissionHandlerInterface $permission_handler
+ * The permission handler.
*/
- public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
+ public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, PermissionHandlerInterface $permission_handler) {
parent::__construct($config_factory);
$this->state = $state;
+ $this->permissionHandler = $permission_handler;
}
/**
@@ -39,7 +50,8 @@ public function __construct(ConfigFactoryInterface $config_factory, StateInterfa
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
- $container->get('state')
+ $container->get('state'),
+ $container->get('user.permissions')
);
}
/**
@@ -61,11 +73,13 @@ protected function getEditableConfigNames() {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('system.maintenance');
+ $permissions = $this->permissionHandler->getPermissions();
+ $permission_label = $permissions['access site in maintenance mode']['title'];
$form['maintenance_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Put site into maintenance mode'),
'#default_value' => $this->state->get('system.maintenance_mode'),
- '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" permission will be able to access the site. Authorized users can log in directly via the user login page.', array(':permissions-url' => $this->url('user.admin_permissions'), ':user-login' => $this->url('user.login'))),
+ '#description' => t('Visitors will only see the maintenance mode message. Only users with the "@permission-label" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permission-label' => $permission_label, ':permissions-url' => $this->url('user.admin_permissions'), ':user-login' => $this->url('user.login'))),
);
$form['maintenance_mode_message'] = array(
'#type' => 'textarea',
diff --git a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
index fc14b2d2caea2f2f04ef301889cefe621571fc79..84e34921b4c36264c0d4511b69fb14c79698c42a 100644
--- a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
+++ b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
@@ -39,6 +39,15 @@ protected function setUp() {
* Verifies site maintenance mode functionality.
*/
protected function testSiteMaintenance() {
+
+ // Verify that permission message is displayed.
+ $permission_handler = $this->container->get('user.permissions');
+ $permissions = $permission_handler->getPermissions();
+ $permission_label = $permissions['access site in maintenance mode']['title'];
+ $permission_message = t('Visitors will only see the maintenance mode message. Only users with the "@permission-label" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permission-label' => $permission_label, ':permissions-url' => \Drupal::url('user.admin_permissions'), ':user-login' => \Drupal::url('user.login')));
+ $this->drupalGet(Url::fromRoute('system.site_maintenance_mode'));
+ $this->assertRaw($permission_message, 'Found the permission message.');
+
$this->drupalGet(Url::fromRoute('user.page'));
// JS should be aggregated, so drupal.js is not in the page source.
$links = $this->xpath('//script[contains(@src, :href)]', array(':href' => '/core/misc/drupal.js'));