function WorkspaceSwitcherForm::submitForm
Same name in other branches
- 9 core/modules/workspaces/src/Form/WorkspaceSwitcherForm.php \Drupal\workspaces\Form\WorkspaceSwitcherForm::submitForm()
- 8.9.x core/modules/workspaces/src/Form/WorkspaceSwitcherForm.php \Drupal\workspaces\Form\WorkspaceSwitcherForm::submitForm()
- 11.x core/modules/workspaces/src/Form/WorkspaceSwitcherForm.php \Drupal\workspaces\Form\WorkspaceSwitcherForm::submitForm()
Overrides FormInterface::submitForm
File
-
core/
modules/ workspaces/ src/ Form/ WorkspaceSwitcherForm.php, line 133
Class
- WorkspaceSwitcherForm
- Provides a form that activates a different workspace.
Namespace
Drupal\workspaces\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$id = $form_state->getValue('workspace_id');
/** @var \Drupal\workspaces\WorkspaceInterface $workspace */
$workspace = $this->workspaceStorage
->load($id);
try {
$this->workspaceManager
->setActiveWorkspace($workspace);
$this->messenger
->addMessage($this->t('%workspace_label is now the active workspace.', [
'%workspace_label' => $workspace->label(),
]));
} catch (WorkspaceAccessException $e) {
$this->messenger
->addError($this->t('You do not have access to activate the %workspace_label workspace.', [
'%workspace_label' => $workspace->label(),
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.