You are here

public function RequireLoginSettingsForm::buildForm in Require Login 8.2

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/RequireLoginSettingsForm.php, line 59

Class

RequireLoginSettingsForm
Configure Require Login settings for this site.

Namespace

Drupal\require_login\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('require_login.config');

  // Basic settings.
  $form['auth_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Login path'),
    '#description' => $this
      ->t('Path to the user login page. Default: /user/login'),
    '#default_value' => $config
      ->get('auth_path') ? $config
      ->get('auth_path') : '/user/login',
  ];
  $form['destination_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Login destination'),
    '#description' => $this
      ->t('Predetermined post-login destination path. Leave blank for the default behavior.'),
    '#default_value' => $config
      ->get('destination_path'),
  ];
  $form['deny_message'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Access denied message'),
    '#description' => $this
      ->t('Show message to user attempting to access a restricted page. Leave blank to disable.'),
    '#default_value' => $config
      ->get('deny_message'),
  ];
  $items = [
    '#theme' => 'item_list',
    '#prefix' => $this
      ->t('Exclude authentication checks on specific paths. <strong>Limit one path per line.</strong>'),
    '#items' => [
      $this
        ->t('Use &lt;front&gt; to exclude the front page.'),
      $this
        ->t('Use internal paths to exclude site pages. <em>I.E. /about/contact</em>'),
      $this
        ->t('Use URL parameters to further refine path matches. <em>I.E. /blog?year=current</em>'),
      $this
        ->t('Use wildcards (*) to match any part of a path. <em>I.E. /shop/*/orders</em>'),
    ],
  ];
  $form['excluded_paths'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Excluded paths'),
    '#description' => render($items),
    '#default_value' => $config
      ->get('excluded_paths'),
  ];
  $node_types = $config
    ->get('excluded_node_types');
  $form['excluded_node_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Excluded content types'),
    '#description' => $this
      ->t('Exclude authentication checks on all pages of a specific content type.'),
    '#options' => node_type_get_names(),
    '#multiple' => TRUE,
    '#default_value' => $node_types ? $node_types : [],
  ];

  // Additional settings.
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced settings'),
  ];
  $form['advanced']['excluded_403'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Exclude 403 (access denied) page'),
    '#description' => $this
      ->t('Allow unauthenticated access to the 403 (access denied) page.'),
    '#default_value' => $config
      ->get('excluded_403'),
  ];
  $form['advanced']['excluded_404'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Exclude 404 (not found) page'),
    '#description' => $this
      ->t('Allow unauthenticated access to the 404 (not found) page.'),
    '#default_value' => $config
      ->get('excluded_404'),
  ];
  $form['advanced']['excluded_routes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Excluded route names'),
    '#description' => $this
      ->t('Exclude authentication checks on specific route names. <strong>Limit one path per line.</strong>'),
    '#default_value' => $config
      ->get('excluded_routes'),
  ];
  return parent::buildForm($form, $form_state);
}