function SiteMaintenanceModeForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/system/src/Form/SiteMaintenanceModeForm.php \Drupal\system\Form\SiteMaintenanceModeForm::buildForm()
  2. 10 core/modules/system/src/Form/SiteMaintenanceModeForm.php \Drupal\system\Form\SiteMaintenanceModeForm::buildForm()
  3. 11.x core/modules/system/src/Form/SiteMaintenanceModeForm.php \Drupal\system\Form\SiteMaintenanceModeForm::buildForm()

Overrides ConfigFormBase::buildForm

File

core/modules/system/src/Form/SiteMaintenanceModeForm.php, line 78

Class

SiteMaintenanceModeForm
Configure maintenance settings for this site.

Namespace

Drupal\system\Form

Code

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'] = [
        '#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 "@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.', [
            '@permission-label' => $permission_label,
            ':permissions-url' => Url::fromRoute('user.admin_permissions')->toString(),
            ':user-login' => Url::fromRoute('user.login')->toString(),
        ]),
    ];
    $form['maintenance_mode_message'] = [
        '#type' => 'textarea',
        '#title' => t('Message to display when in maintenance mode'),
        '#default_value' => $config->get('message'),
    ];
    return parent::buildForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.