function SiteMaintenanceModeForm::buildForm

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

Overrides ConfigFormBase::buildForm

File

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

Class

SiteMaintenanceModeForm
Configure maintenance settings for this site.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $permissions = $this->permissionHandler
        ->getPermissions();
    $permission_label = $permissions['access site in maintenance mode']['title'];
    $form['maintenance_mode'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Put site into maintenance mode'),
        '#default_value' => $this->state
            ->get('system.maintenance_mode'),
        '#description' => $this->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' => $this->t('Message to display when in maintenance mode'),
        '#config_target' => 'system.maintenance: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.