function WorkflowTransitionEditForm::form

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

Overrides EntityForm::form

File

core/modules/workflows/src/Form/WorkflowTransitionEditForm.php, line 73

Class

WorkflowTransitionEditForm
Class WorkflowTransitionEditForm.

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();
    $transition = $workflow->getTypePlugin()
        ->getTransition($this->transitionId);
    $form['label'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Transition label'),
        '#maxlength' => 255,
        '#default_value' => $transition->label(),
        '#required' => TRUE,
    ];
    $form['id'] = [
        '#type' => 'value',
        '#value' => $this->transitionId,
    ];
    // @todo https://www.drupal.org/node/2830584 Add some ajax to ensure that
    //   only valid transitions are selectable.
    $states = array_map([
        State::class,
        'labelCallback',
    ], $workflow->getTypePlugin()
        ->getStates());
    $form['from'] = [
        '#type' => 'checkboxes',
        '#title' => $this->t('From'),
        '#required' => TRUE,
        '#default_value' => array_keys($transition->from()),
        '#options' => $states,
    ];
    $form['to'] = [
        '#type' => 'radios',
        '#title' => $this->t('To'),
        '#required' => TRUE,
        '#default_value' => $transition->to()
            ->id(),
        '#options' => $states,
        '#disabled' => TRUE,
    ];
    // Add additional form fields from the workflow type plugin.
    if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
        $form['type_settings'] = [
            '#tree' => TRUE,
        ];
        $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
        $subform_state->set('transition', $transition);
        $form['type_settings'] += $this->pluginFormFactory
            ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
            ->buildConfigurationForm($form['type_settings'], $subform_state);
    }
    return $form;
}

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