Commit 73078ed5 authored by alexpott's avatar alexpott

Issue #2731861 by maxocub, felribeiro, aneek, alauzon, rajeshwari10, malavya,...

Issue #2731861 by maxocub, felribeiro, aneek, alauzon, rajeshwari10, malavya, Sagar Ramgade, visabhishek, pashupathi nath gajawada, starshaped, quietone: Maintenance mode description shows wrong permission name
parent a4dd7f28
......@@ -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" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> 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" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> 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',
......
......@@ -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" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> 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'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment