You are here

public function WorkflowStateAddForm::form in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workflows/src/Form/WorkflowStateAddForm.php \Drupal\workflows\Form\WorkflowStateAddForm::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/WorkflowStateAddForm.php, line 56

Class

WorkflowStateAddForm
Class WorkflowStateAddForm.

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
    ->getEntity();
  $workflow_type = $workflow
    ->getTypePlugin();
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('State label'),
    '#maxlength' => 255,
    '#default_value' => '',
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#machine_name' => [
      'exists' => [
        $this,
        'exists',
      ],
    ],
  ];
  if ($workflow_type
    ->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
    $form['type_settings'] = [
      '#tree' => TRUE,
    ];
    $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
    $form['type_settings'] += $this->pluginFormFactory
      ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
      ->buildConfigurationForm($form['type_settings'], $subform_state);
  }
  return $form;
}