You are here

public function WorkspaceActivateFormBase::validateForm in Workspace 8

Form validation handler.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/WorkspaceActivateFormBase.php, line 48

Class

WorkspaceActivateFormBase
The base class for forms that activate a workspace.

Namespace

Drupal\workspace\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $id = $form_state
    ->getValue('workspace_id');

  // Ensure we are given an ID.
  if (!$id) {
    $form_state
      ->setErrorByName('workspace_id', 'The workspace ID is required.');
  }

  // Ensure the workspace by that id exists.

  /** @var WorkspaceInterface $workspace */
  $workspace = $this->entityTypeManager
    ->getStorage('workspace')
    ->load($id);
  if (!$workspace) {
    $form_state
      ->setErrorByName('workspace_id', 'This workspace no longer exists.');
  }
}