You are here

public function PermissionsForm::validateForm in Filter Permissions 8

Form validation 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 FormBase::validateForm

File

src/Form/PermissionsForm.php, line 255

Class

PermissionsForm
Provides an enhanced user permissions administration form.

Namespace

Drupal\filter_perms\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $submit_button = $form_state
    ->getTriggeringElement();

  // no need to run this validation when submitting filter changes
  if ($submit_button['#value']
    ->render() == 'Save permissions') {
    $submitted_roles = $form_state
      ->getValue('role_names');
    $permissions_form = $form_state
      ->getValue('permissions');

    // check that the $form_state has not been updated since creation of this submitted form
    if (count(array_diff($permissions_form['displayed_roles'], $submitted_roles))) {
      $form_state
        ->setError($form['filters']['container']['roles'], t('The submitted form contains outdated permissions checkboxes and has not been saved. Please re-filter and try again.'));
    }
  }
}