function WorkflowAddForm::form

Same name in other branches
  1. 8.9.x core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::form()
  2. 10 core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::form()
  3. 11.x core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::form()

Overrides EntityForm::form

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;
}

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