Commit f7f742ef authored by larowlan's avatar larowlan

Issue #2896722 by Sam152, Wim Leers, tim.plunkett, larowlan, timmillwood:...

Issue #2896722 by Sam152, Wim Leers, tim.plunkett, larowlan, timmillwood: Leverage PluginWithFormsInterface to encapsulate @WorkflowType schema and clean up state/transition form methods
parent cd0a65b2
content_moderation.workflow_type_edit_form:
path: '/admin/config/workflow/workflows/manage/{workflow}/type/{entity_type_id}'
defaults:
_form: '\Drupal\content_moderation\Form\WorkflowTypeEditForm'
_title_callback: '\Drupal\content_moderation\Form\WorkflowTypeEditForm::getTitle'
_form: '\Drupal\content_moderation\Form\ContentModerationConfigureEntityTypesForm'
_title_callback: '\Drupal\content_moderation\Form\ContentModerationConfigureEntityTypesForm::getTitle'
requirements:
_permission: 'administer workflows'
......@@ -18,7 +18,7 @@
/**
* The form for editing entity types associated with a workflow.
*/
class WorkflowTypeEditForm extends FormBase {
class ContentModerationConfigureEntityTypesForm extends FormBase {
/**
* The entity type manager service.
......
<?php
namespace Drupal\content_moderation\Form;
use Drupal\Component\Serialization\Json;
use Drupal\content_moderation\ModerationInformationInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\workflows\Plugin\WorkflowTypeConfigureFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The content moderation WorkflowType configuration form.
*
* @see \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration
*/
class ContentModerationConfigureForm extends WorkflowTypeConfigureFormBase implements ContainerInjectionInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The moderation info service.
*
* @var \Drupal\content_moderation\ModerationInformationInterface
*/
protected $moderationInfo;
/**
* The entity type type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Create an instance of ContentModerationConfigureForm.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, ModerationInformationInterface $moderationInformation, EntityTypeBundleInfoInterface $entityTypeBundleInfo) {
$this->entityTypeManager = $entityTypeManager;
$this->moderationInfo = $moderationInformation;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('content_moderation.moderation_information'),
$container->get('entity_type.bundle.info')
);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$workflow = $form_state->getFormObject()->getEntity();
$header = [
'type' => $this->t('Items'),
'operations' => $this->t('Operations')
];
$form['entity_types_container'] = [
'#type' => 'details',
'#title' => $this->t('This workflow applies to:'),
'#open' => TRUE,
];
$form['entity_types_container']['entity_types'] = [
'#type' => 'table',
'#header' => $header,
'#empty' => $this->t('There are no entity types.'),
];
$entity_types = $this->entityTypeManager->getDefinitions();
foreach ($entity_types as $entity_type) {
if (!$this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
continue;
}
$selected_bundles = [];
foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle) {
if ($this->workflowType->appliesToEntityTypeAndBundle($entity_type->id(), $bundle_id)) {
$selected_bundles[$bundle_id] = $bundle['label'];
}
}
$form['entity_types_container']['entity_types'][$entity_type->id()] = [
'type' => [
'label' => ['#markup' => '<strong>' . $this->t('@bundle types', ['@bundle' => $entity_type->getLabel()]) . '</strong>'],
'selected' => [
'#prefix' => '<br/><span id="selected-' . $entity_type->id() . '">',
'#markup' => !empty($selected_bundles) ? implode(', ', $selected_bundles) : $this->t('none'),
'#suffix' => '</span>',
],
],
'operations' => [
'#type' => 'operations',
'#links' => [
'select' => [
'title' => $this->t('Select'),
'url' => Url::fromRoute('content_moderation.workflow_type_edit_form', ['workflow' => $workflow->id(), 'entity_type_id' => $entity_type->id()]),
'attributes' => [
'aria-label' => $this->t('Select'),
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
],
],
],
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
// Configuration is updated from modal windows launched from this form, no
// need to change any configuration here.
}
}
<?php
namespace Drupal\content_moderation\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\workflows\Plugin\WorkflowTypeStateFormBase;
use Drupal\workflows\StateInterface;
/**
* The content moderation state form.
*
* @see \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration
*/
class ContentModerationStateForm extends WorkflowTypeStateFormBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, StateInterface $state = NULL) {
/** @var \Drupal\content_moderation\ContentModerationState $state */
$state = $form_state->get('state');
$is_required_state = isset($state) ? in_array($state->id(), $this->workflowType->getRequiredStates(), TRUE) : FALSE;
$form = [];
$form['published'] = [
'#type' => 'checkbox',
'#title' => $this->t('Published'),
'#description' => $this->t('When content reaches this state it should be published.'),
'#default_value' => isset($state) ? $state->isPublishedState() : FALSE,
'#disabled' => $is_required_state,
];
$form['default_revision'] = [
'#type' => 'checkbox',
'#title' => $this->t('Default revision'),
'#description' => $this->t('When content reaches this state it should be made the default revision; this is implied for published states.'),
'#default_value' => isset($state) ? $state->isDefaultRevisionState() : FALSE,
'#disabled' => $is_required_state,
// @todo Add form #state to force "make default" on when "published" is
// on for a state.
// @see https://www.drupal.org/node/2645614
];
return $form;
}
}
......@@ -2,19 +2,16 @@
namespace Drupal\content_moderation\Plugin\WorkflowType;
use Drupal\Component\Serialization\Json;
use Drupal\content_moderation\ModerationInformationInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\content_moderation\ContentModerationState;
use Drupal\Core\Url;
use Drupal\workflows\Plugin\WorkflowTypeFormBase;
use Drupal\workflows\Plugin\WorkflowTypeBase;
use Drupal\workflows\StateInterface;
use Drupal\workflows\WorkflowInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -29,9 +26,13 @@
* "draft",
* "published",
* },
* forms = {
* "configure" = "\Drupal\content_moderation\Form\ContentModerationConfigureForm",
* "state" = "\Drupal\content_moderation\Form\ContentModerationStateForm"
* },
* )
*/
class ContentModeration extends WorkflowTypeFormBase implements ContainerFactoryPluginInterface {
class ContentModeration extends WorkflowTypeBase implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
......@@ -144,35 +145,6 @@ public function workflowStateHasData(WorkflowInterface $workflow, StateInterface
->execute();
}
/**
* {@inheritdoc}
*/
public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) {
/** @var \Drupal\content_moderation\ContentModerationState $state */
$is_required_state = isset($state) ? in_array($state->id(), $this->getRequiredStates(), TRUE) : FALSE;
$form = [];
$form['published'] = [
'#type' => 'checkbox',
'#title' => $this->t('Published'),
'#description' => $this->t('When content reaches this state it should be published.'),
'#default_value' => isset($state) ? $state->isPublishedState() : FALSE,
'#disabled' => $is_required_state,
];
$form['default_revision'] = [
'#type' => 'checkbox',
'#title' => $this->t('Default revision'),
'#description' => $this->t('When content reaches this state it should be made the default revision; this is implied for published states.'),
'#default_value' => isset($state) ? $state->isDefaultRevisionState() : FALSE,
'#disabled' => $is_required_state,
// @todo Add form #state to force "make default" on when "published" is
// on for a state.
// @see https://www.drupal.org/node/2645614
];
return $form;
}
/**
* Gets the entity types the workflow is applied to.
*
......@@ -375,68 +347,4 @@ public function getInitialState(WorkflowInterface $workflow, $entity = NULL) {
return parent::getInitialState($workflow);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL) {
$header = [
'type' => $this->t('Items'),
'operations' => $this->t('Operations')
];
$form['entity_types_container'] = [
'#type' => 'details',
'#title' => $this->t('This workflow applies to:'),
'#open' => TRUE,
];
$form['entity_types_container']['entity_types'] = [
'#type' => 'table',
'#header' => $header,
'#empty' => $this->t('There are no entity types.'),
];
$entity_types = $this->entityTypeManager->getDefinitions();
foreach ($entity_types as $entity_type) {
if (!$this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
continue;
}
$selected_bundles = [];
foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle) {
if ($this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle_id)) {
$selected_bundles[$bundle_id] = $bundle['label'];
}
}
$form['entity_types_container']['entity_types'][$entity_type->id()] = [
'type' => [
'label' => ['#markup' => '<strong>' . $this->t('@bundle types', ['@bundle' => $entity_type->getLabel()]) . '</strong>'],
'selected' => [
'#prefix' => '<br/><span id="selected-' . $entity_type->id() . '">',
'#markup' => !empty($selected_bundles) ? implode(', ', $selected_bundles) : $this->t('none'),
'#suffix' => '</span>',
],
],
'operations' => [
'#type' => 'operations',
'#links' => [
'select' => [
'title' => $this->t('Select'),
'url' => Url::fromRoute('content_moderation.workflow_type_edit_form', ['workflow' => $workflow->id(), 'entity_type_id' => $entity_type->id()]),
'attributes' => [
'aria-label' => $this->t('Select'),
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
],
],
],
];
}
return $form;
}
}
......@@ -62,8 +62,8 @@ public function testNewWorkflow() {
$this->submitForm([
'label' => 'Test State',
'id' => 'test_state',
'type_settings[content_moderation][published]' => TRUE,
'type_settings[content_moderation][default_revision]' => FALSE,
'type_settings[published]' => TRUE,
'type_settings[default_revision]' => FALSE,
], 'Save');
$this->assertSession()->pageTextContains('Created Test State state.');
$this->assertSession()->linkByHrefExists('/admin/config/workflow/workflows/manage/test_workflow/state/test_state/delete');
......@@ -78,13 +78,13 @@ public function testNewWorkflow() {
// Ensure that the published settings cannot be changed.
$this->drupalGet('admin/config/workflow/workflows/manage/test_workflow/state/published');
$this->assertSession()->fieldDisabled('type_settings[content_moderation][published]');
$this->assertSession()->fieldDisabled('type_settings[content_moderation][default_revision]');
$this->assertSession()->fieldDisabled('type_settings[published]');
$this->assertSession()->fieldDisabled('type_settings[default_revision]');
// Ensure that the draft settings cannot be changed.
$this->drupalGet('admin/config/workflow/workflows/manage/test_workflow/state/draft');
$this->assertSession()->fieldDisabled('type_settings[content_moderation][published]');
$this->assertSession()->fieldDisabled('type_settings[content_moderation][default_revision]');
$this->assertSession()->fieldDisabled('type_settings[published]');
$this->assertSession()->fieldDisabled('type_settings[default_revision]');
}
}
......@@ -50,4 +50,23 @@ class WorkflowType extends Plugin {
*/
public $required_states = [];
/**
* A list of optional form classes implementing PluginFormInterface.
*
* Forms which will be used for the workflow UI are 'configure', 'state' and
* 'transition'.
*
* @see \Drupal\Core\Plugin\PluginWithFormsInterface
* @see \Drupal\Core\Plugin\PluginFormInterface
* @see \Drupal\workflows\Plugin\WorkflowTypeConfigureFormBase
* @see \Drupal\workflows\Plugin\WorkflowTypeStateFormBase
* @see \Drupal\workflows\Plugin\WorkflowTypeTransitionFormBase
* @see \Drupal\workflows\WorkflowTypeInterface::PLUGIN_FORM_KEY
* @see \Drupal\workflows\StateInterface::PLUGIN_FORM_KEY
* @see \Drupal\workflows\TransitionInterface::PLUGIN_FORM_KEY
*
* @var array
*/
public $forms = [];
}
......@@ -3,19 +3,47 @@
namespace Drupal\workflows\Form;
use Drupal\Core\Form\SubformState;
use Drupal\workflows\WorkflowTypeFormInterface;
use Drupal\Core\Plugin\PluginFormFactoryInterface;
use Drupal\workflows\Entity\Workflow;
use Drupal\workflows\State;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\workflows\WorkflowTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The form for editing workflows.
*/
class WorkflowEditForm extends EntityForm {
/**
* The plugin form factory.
*
* @var \Drupal\Core\Plugin\PluginFormFactoryInterface
*/
protected $pluginFormFactory;
/**
* Creates an instance of WorkflowStateEditForm.
*
* @param \Drupal\Core\Plugin\PluginFormFactoryInterface $pluginFormFactory
* The plugin form factory.
*/
public function __construct(PluginFormFactoryInterface $pluginFormFactory) {
$this->pluginFormFactory = $pluginFormFactory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin_form.factory')
);
}
/**
* {@inheritdoc}
*/
......@@ -24,6 +52,7 @@ public function form(array $form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
$workflow_type = $workflow->getTypePlugin();
$form['#title'] = $this->t('Edit %label workflow', ['%label' => $workflow->label()]);
$form['label'] = [
......@@ -184,12 +213,14 @@ public function form(array $form, FormStateInterface $form_state) {
'#markup' => $workflow->toLink($this->t('Add a new transition'), 'add-transition-form')->toString(),
];
if ($workflow->getTypePlugin() instanceof WorkflowTypeFormInterface) {
if ($workflow_type->hasFormClass(WorkflowTypeInterface::PLUGIN_FORM_KEY)) {
$form['type_settings'] = [
'#tree' => TRUE,
];
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$form['type_settings'] += $workflow->getTypePlugin()->buildConfigurationForm($form['type_settings'], $subform_state, $workflow);
$form['type_settings'] += $this->pluginFormFactory
->createInstance($workflow_type, WorkflowTypeInterface::PLUGIN_FORM_KEY)
->buildConfigurationForm($form['type_settings'], $subform_state);
}
return $form;
......@@ -201,9 +232,13 @@ public function form(array $form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
if ($workflow->getTypePlugin() instanceof WorkflowTypeFormInterface) {
$workflow_type = $workflow->getTypePlugin();
if ($workflow_type->hasFormClass(WorkflowTypeInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$workflow->getTypePlugin()->validateConfigurationForm($form['type_settings'], $subform_state);
$this->pluginFormFactory
->createInstance($workflow_type, WorkflowTypeInterface::PLUGIN_FORM_KEY)
->validateConfigurationForm($form['type_settings'], $subform_state);
}
}
......@@ -213,12 +248,16 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
public function save(array $form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
if ($workflow->getTypePlugin() instanceof WorkflowTypeFormInterface) {
$workflow_type = $workflow->getTypePlugin();
if ($workflow_type->hasFormClass(WorkflowTypeInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$workflow->getTypePlugin()->submitConfigurationForm($form['type_settings'], $subform_state);
$this->pluginFormFactory
->createInstance($workflow_type, WorkflowTypeInterface::PLUGIN_FORM_KEY)
->submitConfigurationForm($form['type_settings'], $subform_state);
}
$workflow->save();
$workflow->save();
drupal_set_message($this->t('Saved the %label Workflow.', ['%label' => $workflow->label()]));
}
......
......@@ -5,12 +5,42 @@
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\Core\Plugin\PluginFormFactoryInterface;
use Drupal\workflows\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class WorkflowStateAddForm.
*/
class WorkflowStateAddForm extends EntityForm {
/**
* The plugin form factory.
*
* @var \Drupal\Core\Plugin\PluginFormFactoryInterface
*/
protected $pluginFormFactory;
/**
* Creates an instance of WorkflowStateEditForm.
*
* @param \Drupal\Core\Plugin\PluginFormFactoryInterface $pluginFormFactory
* The plugin form factory.
*/
public function __construct(PluginFormFactoryInterface $pluginFormFactory) {
$this->pluginFormFactory = $pluginFormFactory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin_form.factory')
);
}
/**
* {@inheritdoc}
*/
......@@ -26,6 +56,8 @@ public function form(array $form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->getEntity();
$workflow_type = $workflow->getTypePlugin();
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
......@@ -42,11 +74,15 @@ public function form(array $form, FormStateInterface $form_state) {
],
];
// Add additional form fields from the workflow type plugin.
if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
$form['type_settings'] = [
$workflow->get('type') => $workflow->getTypePlugin()->buildStateConfigurationForm($form_state, $workflow),
'#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;
}
......@@ -81,18 +117,30 @@ public function exists($state_id) {
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
$type_plugin = $entity->getTypePlugin();
// Replicate the validation that Workflow::addState() does internally as the
// form values have not been validated at this point.
if (!$entity->getTypePlugin()->hasState($values['id']) && !preg_match('/[^a-z0-9_]+/', $values['id'])) {
$entity->getTypePlugin()->addState($values['id'], $values['label']);
if (isset($values['type_settings'])) {
$configuration = $entity->getTypePlugin()->getConfiguration();
// @todo move to submitStateConfigurationForm. #2849827.
$configuration['states'][$values['id']] += $values['type_settings'][$entity->getTypePlugin()->getPluginId()];
$entity->set('type_settings', $configuration);
if (!$type_plugin->hasState($values['id']) && !preg_match('/[^a-z0-9_]+/', $values['id'])) {
$type_plugin->addState($values['id'], $values['label']);
}
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
/** @var \Drupal\workflows\WorkflowTypeInterface $workflow_type */
$workflow = $this->entity;
$workflow_type = $workflow->getTypePlugin();
if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$this->pluginFormFactory
->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
->validateConfigurationForm($form['type_settings'], $subform_state);
}
}
/**
......@@ -101,6 +149,17 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
$workflow_type = $workflow->getTypePlugin();
$state = $workflow_type->getState($form_state->getValue('id'));
if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$subform_state->set('state', $state);
$this->pluginFormFactory
->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
->submitConfigurationForm($form['type_settings'], $subform_state);
}
$workflow->save();
drupal_set_message($this->t('Created %label state.', [
'%label' => $workflow->getTypePlugin()->getState($form_state->getValue('id'))->label(),
......
......@@ -5,7 +5,11 @@
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\Core\Plugin\PluginFormFactoryInterface;
use Drupal\Core\Url;
use Drupal\workflows\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class WorkflowStateEditForm.
......@@ -19,6 +23,32 @@ class WorkflowStateEditForm extends EntityForm {
*/
protected $stateId;
/**
* The plugin form factory.
*
* @var \Drupal\Core\Plugin\PluginFormFactoryInterface
*/
protected $pluginFormFactory;
/**
* Creates an instance of WorkflowStateEditForm.
*
* @param \Drupal\Core\Plugin\PluginFormFactoryInterface $pluginFormFactory
* The plugin form factory.
*/
public function __construct(PluginFormFactoryInterface $pluginFormFactory) {
$this->pluginFormFactory = $pluginFormFactory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin_form.factory')
);
}
/**
* {@inheritdoc}
*/
......@@ -42,7 +72,9 @@ public function form(array $form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->getEntity();
$workflow_type = $workflow->getTypePlugin();
$state = $workflow->getTypePlugin()->getState($this->stateId);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
......@@ -62,10 +94,16 @@ public function form(array $form, FormStateInterface $form_state) {
];
// Add additional form fields from the workflow type plugin.
if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {