You are here

public function WorkflowAddForm::form in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

core/modules/workflows/src/Form/WorkflowAddForm.php, line 48

Class

WorkflowAddForm
Form for adding workflows.

Namespace

Drupal\workflows\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /* @var \Drupal\workflows\WorkflowInterface $workflow */
  $workflow = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $workflow
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $workflow
      ->id(),
    '#machine_name' => [
      'exists' => [
        Workflow::class,
        'load',
      ],
    ],
  ];
  $workflow_types = array_column($this->workflowTypePluginManager
    ->getDefinitions(), 'label', 'id');
  $form['workflow_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Workflow type'),
    '#required' => TRUE,
    '#options' => $workflow_types,
  ];
  return $form;
}