You are here

WorkflowTypeConfigureForm.php in Workflows Field 8

Same filename and directory in other branches
  1. 2.x src/Form/WorkflowTypeConfigureForm.php

File

src/Form/WorkflowTypeConfigureForm.php
View source
<?php

namespace Drupal\workflows_field\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\workflows\Plugin\WorkflowTypeConfigureFormBase;
use Drupal\workflows\State;

/**
 * Plugin form for the workflows field.
 */
class WorkflowTypeConfigureForm extends WorkflowTypeConfigureFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $configuration = $this->workflowType
      ->getConfiguration();
    $form['settings'] = [
      '#title' => $this
        ->t('Workflow Settings'),
      '#type' => 'fieldset',
    ];
    $labels = array_map([
      State::class,
      'labelCallback',
    ], $this->workflowType
      ->getStates());
    $form['settings']['initial_state'] = [
      '#title' => $this
        ->t('Initial State'),
      '#type' => 'select',
      '#default_value' => isset($configuration['initial_state']) ? $configuration['initial_state'] : NULL,
      '#options' => $labels,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $configuration = $this->workflowType
      ->getConfiguration();
    $configuration['initial_state'] = $form_state
      ->getValue([
      'settings',
      'initial_state',
    ]);
    $this->workflowType
      ->setConfiguration($configuration);
  }

}

Classes

Namesort descending Description
WorkflowTypeConfigureForm Plugin form for the workflows field.