function FormOperations::formAlter
Same name in this branch
- 11.x core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::formAlter()
Same name in other branches
- 9 core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::formAlter()
- 8.9.x core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::formAlter()
- 10 core/modules/workspaces/src/FormOperations.php \Drupal\workspaces\FormOperations::formAlter()
Implements hook_form_alter().
File
-
core/
modules/ workspaces/ src/ Hook/ FormOperations.php, line 25
Class
- FormOperations
- Defines a class for reacting to form operations.
Namespace
Drupal\workspaces\HookCode
public function formAlter(array &$form, FormStateInterface $form_state, $form_id) : void {
// No alterations are needed if we're not in a workspace context.
if (!$this->workspaceManager
->hasActiveWorkspace()) {
return;
}
// Add a validation step for every form if we are in a workspace.
$this->addWorkspaceValidation($form);
// If a form has already been marked as safe or not to submit in a
// workspace, we don't have anything else to do.
if ($form_state->has('workspace_safe')) {
return;
}
$form_object = $form_state->getFormObject();
$workspace_safe = $form_object instanceof WorkspaceSafeFormInterface || $form_object instanceof WorkspaceDynamicSafeFormInterface && $form_object->isWorkspaceSafeForm($form, $form_state);
$form_state->set('workspace_safe', $workspace_safe);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.