You are here

public function ProtectedPagesEditForm::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 FormInterface::buildForm

File

src/Form/ProtectedPagesEditForm.php, line 100

Class

ProtectedPagesEditForm
Provides an edit protected page form.

Namespace

Drupal\protected_pages\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
  $fields = [
    'path',
  ];
  $conditions = [];
  $conditions['general'][] = [
    'field' => 'pid',
    'value' => $pid,
    'operator' => '=',
  ];
  $path = $this->protectedPagesStorage
    ->loadProtectedPage($fields, $conditions, TRUE);
  $form['rules_list'] = [
    '#title' => $this
      ->t("Edit Protected Page relative path and password."),
    '#type' => 'details',
    '#description' => $this
      ->t('Please enter the relative path and its corresponding
    password. When user opens this url, they will asked to enter password to
    view this page. For example, "/node/5", "/new-events" etc.'),
    '#open' => TRUE,
  ];
  $form['rules_list']['path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Relative path'),
    '#default_value' => $path,
    '#description' => $this
      ->t('Enter relative Drupal path. For example, "/node/5", "/new-events" etc.'),
    '#required' => TRUE,
  ];
  $form['rules_list']['password'] = [
    '#type' => 'password_confirm',
    '#size' => 25,
  ];
  $form['rules_list']['pid'] = [
    '#type' => 'hidden',
    '#value' => $pid,
  ];
  $form['rules_list']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  return $form;
}