You are here

public function ProtectedPagesSettingForm::buildForm in Protected Pages 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/ProtectedPagesSettingForm.php, line 105

Class

ProtectedPagesSettingForm
Provides protected pages settings configuration form.

Namespace

Drupal\protected_pages\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $config = $this
    ->config('protected_pages.settings');
  $form['protected_pages_password_fieldset'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Protected Pages password settings'),
    '#description' => $this
      ->t('Configure password related settings.'),
    '#open' => TRUE,
  ];
  $global_password_help_text = [];
  $global_password_help_text[] = $this
    ->t('Allow per page password = Only per page password will be accepted. Global password will not be accepted.');
  $global_password_help_text[] = $this
    ->t('Allow per page password or Global password = Per page  password and global password both will be accepted.');
  $global_password_help_text[] = $this
    ->t('Allow Only Global = Only global password will be accepted for each protected page.');
  $global_password_help_text_list = [
    '#theme' => 'item_list',
    '#items' => $global_password_help_text,
    '#title' => $this
      ->t('Please select the appropriate option for protected pages handling.'),
  ];
  $form['protected_pages_password_fieldset']['protected_pages_user_global_password'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Global password setting'),
    '#default_value' => $config
      ->get('password.per_page_or_global'),
    '#options' => [
      'per_page_password' => $this
        ->t('Allow per page password'),
      'per_page_or_global' => $this
        ->t('Allow per page password or Global password'),
      'only_global' => $this
        ->t('Allow only global'),
    ],
    '#description' => $this->renderer
      ->render($global_password_help_text_list),
  ];
  $form['protected_pages_password_fieldset']['protected_pages_global_password_field'] = [
    '#type' => 'password_confirm',
    '#title' => $this
      ->t('Global password'),
    '#description' => $this
      ->t('The default password for all protected pages. This
                                password is necessary if you select the previous checkbox "Allow per page
                                password or Global password" or "Allow Only Global" options above.'),
  ];
  $form['protected_pages_password_fieldset']['protected_pages_session_expire_time'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Session expire time'),
    '#description' => $this
      ->t('When user enters password a session is created.
      The node will be accessible until session expire. Once session expires,
      user will need to enter password again. The default session expire time
      is 0 (unlimited).'),
    '#default_value' => $config
      ->get('password.protected_pages_session_expire_time'),
    '#required' => TRUE,
    '#size' => 10,
    '#element_validate' => [
      [
        $this,
        'protectedPagesValidateIntegerPositive',
      ],
    ],
    '#field_suffix' => $this
      ->t('minutes'),
  ];
  $form['protected_pages_email_fieldset'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Protected Pages email settings'),
    '#description' => $this
      ->t('The following settings allows admin to send emails to multiple users about protected pages details to access protected pages.'),
    '#open' => TRUE,
  ];
  $form['protected_pages_email_fieldset']['protected_pages_email_subject'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Email subject'),
    '#default_value' => $config
      ->get('email.subject'),
    '#description' => $this
      ->t('Enter the subject of the email.'),
  ];
  $form['protected_pages_email_fieldset']['protected_pages_email_body'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Email content'),
    '#rows' => 15,
    '#default_value' => $config
      ->get('email.body'),
    '#description' => $this
      ->t('Enter the body of the email. Only [protected-page-url] and [site-name] tokens are available.
      Since password is encrypted, therefore we can not provide it by token.'),
  ];
  $form['protected_pages_other_fieldset'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Protected Pages other settings'),
    '#description' => $this
      ->t('Configure other settings.'),
    '#open' => TRUE,
  ];
  $form['protected_pages_other_fieldset']['protected_pages_title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Password page title'),
    '#default_value' => $config
      ->get('others.protected_pages_title'),
    '#description' => $this
      ->t('Enter the title of the protected page.'),
  ];
  $form['protected_pages_other_fieldset']['protected_pages_description'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Password page description (inside the field set)'),
    '#default_value' => $config
      ->get('others.protected_pages_description'),
    '#description' => $this
      ->t('Enter specific description for the protected page. This description is displayed inside the fieldset. HTML is accepted.'),
  ];
  $form['protected_pages_other_fieldset']['protected_pages_password_fieldset_legend'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Password fieldset legend'),
    '#default_value' => $config
      ->get('others.protected_pages_password_fieldset_legend'),
    '#description' => $this
      ->t('Enter the text for the password fieldset legend.'),
  ];
  $form['protected_pages_other_fieldset']['protected_pages_password_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Password field label'),
    '#default_value' => $config
      ->get('others.protected_pages_password_label'),
    '#description' => $this
      ->t('Enter the text for the password field label.'),
  ];
  $form['protected_pages_other_fieldset']['protected_pages_submit_button_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Submit button text'),
    '#default_value' => $config
      ->get('others.protected_pages_submit_button_text'),
    '#description' => $this
      ->t('Enter the text for the submit button of enter password form.'),
  ];
  $form['protected_pages_other_fieldset']['protected_pages_incorrect_password_msg'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Incorrect password error text'),
    '#default_value' => $config
      ->get('others.protected_pages_incorrect_password_msg'),
    '#description' => $this
      ->t('This error text will appear if someone enters wrong password in "Enter password screen".'),
  ];
  return $form;
}