You are here

public function WorkspaceSwitcherForm::buildForm in Workspace 8

Same name and namespace in other branches
  1. 8.2 src/Form/WorkspaceSwitcherForm.php \Drupal\workspace\Form\WorkspaceSwitcherForm::buildForm()

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/WorkspaceSwitcherForm.php, line 38

Class

WorkspaceSwitcherForm
Switcher for to activate a different workspace.

Namespace

Drupal\workspace\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, WorkspaceInterface $workspace = NULL) {

  // @todo this form is identical to WorkspaceActivateForm except for this method; can we consolidate forms?
  $form['workspace_id'] = [
    '#type' => 'hidden',
    '#value' => $workspace
      ->id(),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $workspace
      ->label(),
  ];
  $active_workspace = $this->workspaceManager
    ->getActiveWorkspace();
  if ($active_workspace
    ->id() === $workspace
    ->id()) {
    $form['submit']['#attributes']['class'] = [
      'is-active',
    ];
  }
  return $form;
}