function WorkspaceActivateForm::submitForm

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/Form/WorkspaceActivateForm.php \Drupal\workspaces\Form\WorkspaceActivateForm::submitForm()
  2. 8.9.x core/modules/workspaces/src/Form/WorkspaceActivateForm.php \Drupal\workspaces\Form\WorkspaceActivateForm::submitForm()
  3. 10 core/modules/workspaces/src/Form/WorkspaceActivateForm.php \Drupal\workspaces\Form\WorkspaceActivateForm::submitForm()

Overrides EntityForm::submitForm

File

core/modules/workspaces/src/Form/WorkspaceActivateForm.php, line 109

Class

WorkspaceActivateForm
Handle activation of a workspace on administrative pages.

Namespace

Drupal\workspaces\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    try {
        $this->workspaceManager
            ->setActiveWorkspace($this->entity);
        $this->messenger
            ->addMessage($this->t('%workspace_label is now the active workspace.', [
            '%workspace_label' => $this->entity
                ->label(),
        ]));
    } catch (WorkspaceAccessException $e) {
        $this->messenger
            ->addError($this->t('You do not have access to activate the %workspace_label workspace.', [
            '%workspace_label' => $this->entity
                ->label(),
        ]));
    }
    // Redirect to the workspace manage page by default.
    if (!$this->getRequest()->query
        ->has('destination')) {
        $form_state->setRedirectUrl($this->entity
            ->toUrl());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.