You are here

public function AdvbanSettingsForm::buildForm in Advanced ban 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/AdvbanSettingsForm.php, line 67

Class

AdvbanSettingsForm
Configure advban settings for this site.

Namespace

Drupal\advban\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('advban.settings');
  $form['advban_expiry_durations'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Expiry durations'),
    '#default_value' => $config
      ->get('expiry_durations'),
    '#description' => $this
      ->t("Must be in a format that <a href='@strtotime'>PHP's strtotime function</a> can interpret.", [
      '@strtotime' => 'https://php.net/manual/function.strtotime.php',
    ]),
    '#required' => TRUE,
  ];
  $expiry_durations = $this->ipManager
    ->expiryDurations();
  $default_expiry_duration = $config
    ->get('default_expiry_duration');
  $expiry_durations_index = $this->ipManager
    ->expiryDurationIndex($expiry_durations, $default_expiry_duration);
  $form['advban_default_expiry_duration'] = [
    '#title' => $this
      ->t('Default IP ban expiry duration'),
    '#type' => 'select',
    '#options' => [
      AdvbanHelper::ADVBAN_NEVER => $this
        ->t('Never'),
    ] + $expiry_durations,
    '#default_value' => $expiry_durations_index,
    '#description' => $this
      ->t('Select default expiration duration for ban.'),
  ];
  $form['advban_save_last_expiry_duration'] = [
    '#title' => $this
      ->t('Save last IP ban expiry duration'),
    '#type' => 'checkbox',
    '#default_value' => $config
      ->get('save_last_expiry_duration'),
    '#description' => $this
      ->t('Change default expiry duration after each IP ban.'),
  ];
  $form['advban_range_ip_format'] = [
    '#title' => $this
      ->t('Range IP format'),
    '#type' => 'textfield',
    '#default_value' => $config
      ->get('range_ip_format') ?: '@ip_start ... @ip_end',
    '#description' => $this
      ->t('Range IP format for IP list. Use @ip_start, @ip_end variables.'),
  ];
  $form['advban_ban_text'] = [
    '#title' => $this
      ->t('Ban text'),
    '#type' => 'textarea',
    '#default_value' => $config
      ->get('advban_ban_text') ?: '@ip has been banned',
    '#description' => $this
      ->t('Format ban text. Use @ip variable.'),
  ];
  $form['advban_ban_expire_text'] = [
    '#title' => $this
      ->t('Ban text with expire'),
    '#type' => 'textarea',
    '#default_value' => $config
      ->get('advban_ban_expire_text') ?: '@ip has been banned up to @expiry_date',
    '#description' => $this
      ->t('Format ban text with expire date. Use @ip, @expiry_date variables.'),
  ];
  return parent::buildForm($form, $form_state);
}