You are here

public function HstsConfigForm::buildForm in HTTP Strict Transport Security 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/HstsConfigForm.php, line 68
Contains \Drupal\hsts\Form\HstsConfigForm.

Class

HstsConfigForm
Implements a Hsts Config form.

Namespace

Drupal\hsts\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('hsts.settings');
  $form['enabled'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable HSTS'),
    '#description' => t('Whether to start adding the HSTS header information or not.'),
    '#default_value' => $config
      ->get('enabled'),
  ];
  $options = [
    0,
    300,
    31536000,
    63072000,
    94608000,
  ];
  $form['max_age'] = [
    '#type' => 'select',
    '#title' => t('Max age'),
    '#description' => t('The maximum age value for the header. See the <a href="https://tools.ietf.org/html/rfc6797">Strict Transport Security Definition</a> for more information.'),
    '#options' => array_map([
      $this->dateFormatter,
      'formatInterval',
    ], array_combine($options, $options)),
    '#default_value' => $config
      ->get('max_age'),
  ];
  $form['subdomains'] = [
    '#type' => 'checkbox',
    '#title' => t('Include subdomains'),
    '#description' => t('Whether to include the subdomains as part of the HSTS implementation.'),
    '#default_value' => $config
      ->get('subdomains'),
  ];
  $form['preload'] = [
    '#type' => 'checkbox',
    '#title' => t('Preload'),
    '#description' => t('The preload directive allows your domain to be submitted for inclusion by browsers at <a href="https://hstspreload.appspot.com/">hstspreload.appspot.com</a>. Do not enable preload unless you are sure you want all sites on your domain to be HTTPS-only for the long term.'),
    '#default_value' => $config
      ->get('preload'),
  ];
  return parent::buildForm($form, $form_state);
}