You are here

public function WorkspaceForm::form in Workspace 8.2

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/WorkspaceForm.php, line 66

Class

WorkspaceForm
Form controller for the workspace edit forms.

Namespace

Drupal\workspace\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\\workspace\\Entity\\Workspace::load',
    ],
    '#element_validate' => [],
  ];
  return parent::form($form, $form_state);
}