function FormOperations::addWorkspaceValidation
Same name and namespace in other branches
- 11.x core/modules/workspaces/src/Hook/FormOperations.php \Drupal\workspaces\Hook\FormOperations::addWorkspaceValidation()
- 10 core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::addWorkspaceValidation()
- 9 core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::addWorkspaceValidation()
- 8.9.x 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/ Hook/ FormOperations.php - Implements hook_form_alter().
File
-
core/
modules/ workspaces/ src/ Hook/ FormOperations.php, line 88
Class
- FormOperations
- Defines a class for reacting to form operations.
Namespace
Drupal\workspaces\HookCode
protected function addWorkspaceValidation(array &$element) : void {
// 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['#submit'])) {
$element['#validate'][] = [
static::class,
'validateDefaultWorkspace',
];
// Ensure that the workspace validation is always shown, even when the
// form element is limiting validation errors.
if (isset($element['#limit_validation_errors']) && $element['#limit_validation_errors'] !== FALSE) {
$element['#limit_validation_errors'][] = [
'workspace_safe',
];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.