You are here

public function PagesRestrictionSettingsForm::buildForm in Pages Restriction Access 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/PagesRestrictionSettingsForm.php, line 51

Class

PagesRestrictionSettingsForm
Form for configure Pages.

Namespace

Drupal\pages_restriction\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('pages_restriction.settings');
  $form['general_settings'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('General Settings'),
    '#open' => TRUE,
  ];
  $form['general_settings']['pages_restriction'] = [
    '#title' => $this
      ->t('Pages Restriction'),
    '#type' => 'textarea',
    '#description' => $this
      ->t('Insert values with format: <br><br><b>your-url-restricted|your-target</b> Use one per line.<br><br>E.g.  <b>contact/thank-you-for-contacting-us|contact/send-your-message</b>'),
    '#default_value' => $config
      ->get('pages_restriction'),
  ];
  $form['advanced_settings'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced Settings'),
    '#open' => FALSE,
  ];
  $keep_parameters = $config
    ->get('keep_parameters');
  $form['advanced_settings']['keep_parameters'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Keep Parameters'),
    '#default_value' => $keep_parameters,
    '#description' => $this
      ->t('Checking this option Gandalf will keep the parameters on URL.'),
  ];
  $option_roles = [];
  foreach ($this->roles as $key => $role) {
    if (!empty($key) && !empty($role
      ->label())) {
      $option_roles[$key] = $role
        ->label();
    }
  }
  if (!empty($option_roles)) {
    $form['advanced_settings']['bypass_role'] = [
      '#type' => 'checkboxes',
      '#options' => $option_roles,
      '#title' => $this
        ->t('Ignore restrictions for the following roles (bypass)'),
      '#default_value' => $config
        ->get('bypass_role'),
    ];
  }
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}