function ActiveWorkspaceTestForm::buildForm

Same name and namespace in other branches
  1. main core/modules/workspaces/tests/modules/workspaces_test/src/Form/ActiveWorkspaceTestForm.php \Drupal\workspaces_test\Form\ActiveWorkspaceTestForm::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

core/modules/workspaces/tests/modules/workspaces_test/src/Form/ActiveWorkspaceTestForm.php, line 53

Class

ActiveWorkspaceTestForm
Form for testing the active workspace.

Namespace

Drupal\workspaces_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $form['test'] = [
    '#type' => 'textfield',
    '#ajax' => [
      'url' => Url::fromRoute('workspaces_test.get_form'),
      'callback' => function () {
        $this->keyValue
          ->set('ajax_test_active_workspace', $this->workspaceManager
          ->getActiveWorkspace()
          ->id());
        return new AjaxResponse();
      },
    ],
  ];
  $form['collision_test'] = [
    '#type' => 'textfield',
    '#ajax' => [
      'url' => Url::fromRoute('workspaces_test.get_form'),
      'options' => [
        'query' => [
          'media_library_opener_id' => 'test',
        ],
      ],
    ],
  ];
  return $form;
}

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