You are here

protected function FormOperations::addWorkspaceValidation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::addWorkspaceValidation()

Adds our validation handler recursively on each element of a form.

Parameters

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

1 call to FormOperations::addWorkspaceValidation()
FormOperations::formAlter in core/modules/workspaces/src/FormOperations.php
Alters forms to disallow editing in non-default workspaces.

File

core/modules/workspaces/src/FormOperations.php, line 96

Class

FormOperations
Defines a class for reacting to form operations.

Namespace

Drupal\workspaces

Code

protected function addWorkspaceValidation(array &$element) {

  // Recurse through all children and add our validation handler if needed.
  foreach (Element::children($element) as $key) {
    if (isset($element[$key]) && $element[$key]) {
      $this
        ->addWorkspaceValidation($element[$key]);
    }
  }
  if (isset($element['#validate'])) {
    $element['#validate'][] = [
      get_called_class(),
      'validateDefaultWorkspace',
    ];
  }
}