function WorkspaceForm::form

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

Overrides ContentEntityForm::form

File

core/modules/workspaces/src/Form/WorkspaceForm.php, line 66

Class

WorkspaceForm
Form controller for the workspace edit forms.

Namespace

Drupal\workspaces\Form

Code

public function form(array $form, FormStateInterface $form_state) {
    $workspace = $this->entity;
    if ($this->operation == 'edit') {
        $form['#title'] = $this->t('Edit workspace %label', [
            '%label' => $workspace->label(),
        ]);
    }
    $form['label'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Label'),
        '#maxlength' => 255,
        '#default_value' => $workspace->label(),
        '#required' => TRUE,
    ];
    $form['id'] = [
        '#type' => 'machine_name',
        '#title' => $this->t('Workspace ID'),
        '#maxlength' => 255,
        '#default_value' => $workspace->id(),
        '#disabled' => !$workspace->isNew(),
        '#machine_name' => [
            'exists' => '\\Drupal\\workspaces\\Entity\\Workspace::load',
        ],
        '#element_validate' => [],
    ];
    return parent::form($form, $form_state);
}

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