You are here

public function ProtectedPagesAddForm::submitForm in Protected Pages 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/ProtectedPagesAddForm.php, line 166

Class

ProtectedPagesAddForm
Provides an add protected page form.

Namespace

Drupal\protected_pages\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $page_data = [
    'password' => $this->password
      ->hash(Html::escape($form_state
      ->getValue('password'))),
    'path' => Html::escape($form_state
      ->getValue('path')),
  ];
  $pid = $this->protectedPagesStorage
    ->insertProtectedPage($page_data);
  if ($pid) {
    $this->messenger
      ->addMessage($this
      ->t('The protected page settings have been successfully saved.'));
  }
  drupal_flush_all_caches();
  $form_state
    ->setRedirect('protected_pages_list');
}