You are here

public function LibraryActionForm::form in Library 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

src/Form/LibraryActionForm.php, line 19

Class

LibraryActionForm
Action form.

Namespace

Drupal\library\Form

Code

public function form(array $form, FormStateInterface $form_state) : array {
  $form = parent::form($form, $form_state);
  $library_action = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $library_action
      ->label(),
    '#description' => $this
      ->t("Label for the Library action."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $library_action
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\library\\Entity\\LibraryAction::load',
    ],
    '#disabled' => !$library_action
      ->isNew(),
  ];
  $form['action'] = [
    '#title' => 'Action to take',
    '#type' => 'select',
    '#options' => [
      LibraryActionInterface::NO_CHANGE => $this
        ->t('No change in status'),
      LibraryActionInterface::CHANGE_TO_AVAILABLE => $this
        ->t('Change status to available'),
      LibraryActionInterface::CHANGE_TO_UNAVAILABLE => $this
        ->t('Change status to unavailable'),
    ],
    '#default_value' => $library_action
      ->action(),
  ];
  return $form;
}