You are here

public function SettingsForm::buildForm in External Link Pop-up 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/SettingsForm.php, line 39

Class

SettingsForm
Implements the external_link_popup.settings route.

Namespace

Drupal\external_link_popup\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['whitelist'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Trusted domains (whitelist)'),
    '#default_value' => $this
      ->config()
      ->get('whitelist'),
    '#description' => $this
      ->t('Links to these external domain(s) will work normally, without pop-up warning.') . '<br />' . $this
      ->t('Use base domain name without protocol or "www" prefix. Enter one domain per line.'),
  ];
  $form['show_admin'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show on administration pages too.'),
    '#default_value' => $this
      ->config()
      ->get('show_admin'),
  ];
  $form['width'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Default width'),
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
    '#tree' => TRUE,
    '#required' => TRUE,
  ];
  $form['width']['value'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Default width'),
    '#title_display' => 'invisible',
    '#min' => 1,
    '#max' => 4096,
    '#default_value' => $this
      ->config()
      ->get('width.value'),
    '#required' => TRUE,
  ];
  $form['width']['units'] = [
    '#type' => 'select',
    '#options' => [
      '%' => '%',
      'px' => 'px',
    ],
    '#default_value' => $this
      ->config()
      ->get('width.units'),
  ];
  return parent::buildForm($form, $form_state);
}