diff --git a/core/modules/content_moderation/content_moderation.routing.yml b/core/modules/content_moderation/content_moderation.routing.yml
index a7167ca96b18fafc2788b04a14d3d02f6077c660..2ee2c47145c656d6c4022648e284bc60af663bf2 100644
--- a/core/modules/content_moderation/content_moderation.routing.yml
+++ b/core/modules/content_moderation/content_moderation.routing.yml
@@ -1,7 +1,7 @@
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'
diff --git a/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php b/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php
similarity index 99%
rename from core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php
rename to core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php
index b1fe98cfde205c83f945193097db4402f732d89a..3efcafb0d553f96822e4374a41cb26e492287b0e 100644
--- a/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php
+++ b/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php
@@ -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.
diff --git a/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php b/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php
new file mode 100644
index 0000000000000000000000000000000000000000..011b3ee94b373cbdf00b69464c697d3bcf6fed73
--- /dev/null
+++ b/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php
@@ -0,0 +1,136 @@
+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' => '' . $this->t('@bundle types', ['@bundle' => $entity_type->getLabel()]) . ''],
+ 'selected' => [
+ '#prefix' => '
',
+ '#markup' => !empty($selected_bundles) ? implode(', ', $selected_bundles) : $this->t('none'),
+ '#suffix' => '',
+ ],
+ ],
+ '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.
+ }
+
+}
diff --git a/core/modules/content_moderation/src/Form/ContentModerationStateForm.php b/core/modules/content_moderation/src/Form/ContentModerationStateForm.php
new file mode 100644
index 0000000000000000000000000000000000000000..3ba5f659359a9ae945cf1ab114d9ef78b61754f3
--- /dev/null
+++ b/core/modules/content_moderation/src/Form/ContentModerationStateForm.php
@@ -0,0 +1,46 @@
+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;
+ }
+
+}
diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
index c472dc96f3b4d6b520d2380dd631ab0cea4021ec..aac75b98678e0ba80a803a98e638db6965431daa 100644
--- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
+++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
@@ -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' => '' . $this->t('@bundle types', ['@bundle' => $entity_type->getLabel()]) . ''],
- 'selected' => [
- '#prefix' => '
',
- '#markup' => !empty($selected_bundles) ? implode(', ', $selected_bundles) : $this->t('none'),
- '#suffix' => '',
- ],
- ],
- '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;
- }
-
}
diff --git a/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
index 66065ba9f87c74682c7d10a687e8ed077b6269cc..86c658d41e8d96019da6f4256f8a2b699cd2664a 100644
--- a/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
@@ -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]');
}
}
diff --git a/core/modules/workflows/src/Annotation/WorkflowType.php b/core/modules/workflows/src/Annotation/WorkflowType.php
index 6e578ed4b9ed313836557815194be8f6246189b8..755ac706d0c19fcfd44202ccddaf61b1e1431717 100644
--- a/core/modules/workflows/src/Annotation/WorkflowType.php
+++ b/core/modules/workflows/src/Annotation/WorkflowType.php
@@ -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 = [];
+
}
diff --git a/core/modules/workflows/src/Form/WorkflowEditForm.php b/core/modules/workflows/src/Form/WorkflowEditForm.php
index fe59768d112f246547838f060fe6a6ff82ae188a..2f34dc6f1e1d180891b9e4183e8ef91c16c09f14 100644
--- a/core/modules/workflows/src/Form/WorkflowEditForm.php
+++ b/core/modules/workflows/src/Form/WorkflowEditForm.php
@@ -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()]));
}
diff --git a/core/modules/workflows/src/Form/WorkflowStateAddForm.php b/core/modules/workflows/src/Form/WorkflowStateAddForm.php
index bfb38bb947ac4bf26b9764a76af0d39c39c2ce10..ab4a4c1c6501f6e279b6676a985e4f12700fb9b5 100644
--- a/core/modules/workflows/src/Form/WorkflowStateAddForm.php
+++ b/core/modules/workflows/src/Form/WorkflowStateAddForm.php
@@ -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.
- $form['type_settings'] = [
- $workflow->get('type') => $workflow->getTypePlugin()->buildStateConfigurationForm($form_state, $workflow),
- '#tree' => TRUE,
- ];
+ 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;
}
@@ -81,17 +117,29 @@ 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(),
diff --git a/core/modules/workflows/src/Form/WorkflowStateEditForm.php b/core/modules/workflows/src/Form/WorkflowStateEditForm.php
index e8f2a55cd89245399a2d6dc87a886b13bbbf2224..a04998d2873a7ab1bce27cb7077c1a82196026d2 100644
--- a/core/modules/workflows/src/Form/WorkflowStateEditForm.php
+++ b/core/modules/workflows/src/Form/WorkflowStateEditForm.php
@@ -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.
- $form['type_settings'] = [
- $workflow->get('type') => $workflow->getTypePlugin()->buildStateConfigurationForm($form_state, $workflow, $state),
- '#tree' => TRUE,
- ];
+ if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
+ $form['type_settings'] = [
+ '#tree' => TRUE,
+ ];
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $subform_state->set('state', $state);
+ $form['type_settings'] += $this->pluginFormFactory
+ ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
+ ->buildConfigurationForm($form['type_settings'], $subform_state);
+ }
$header = [
'label' => $this->t('Transition'),
@@ -125,10 +163,23 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
$entity->getTypePlugin()->setStateLabel($values['id'], $values['label']);
- if (isset($values['type_settings'])) {
- $configuration = $entity->getTypePlugin()->getConfiguration();
- $configuration['states'][$values['id']] += $values['type_settings'][$entity->getTypePlugin()->getPluginId()];
- $entity->set('type_settings', $configuration);
+ }
+
+ /**
+ * {@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);
+ $subform_state->set('state', $workflow_type->getState($this->stateId));
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
+ ->validateConfigurationForm($form['type_settings'], $subform_state);
}
}
@@ -138,6 +189,16 @@ 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();
+
+ if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $subform_state->set('state', $workflow_type->getState($this->stateId));
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
+ ->submitConfigurationForm($form['type_settings'], $subform_state);
+ }
+
$workflow->save();
drupal_set_message($this->t('Saved %label state.', [
'%label' => $workflow->getTypePlugin()->getState($this->stateId)->label(),
diff --git a/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php b/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php
index 2ffeaff3e45d23042354bb142bca8898b1084e6b..3a582816db8a897c5320085e09b416d4fc63f87a 100644
--- a/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php
+++ b/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php
@@ -5,13 +5,43 @@
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\State;
+use Drupal\workflows\TransitionInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class WorkflowTransitionAddForm.
*/
class WorkflowTransitionAddForm 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}
*/
@@ -27,6 +57,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'),
@@ -62,10 +94,15 @@ public function form(array $form, FormStateInterface $form_state) {
];
// Add additional form fields from the workflow type plugin.
- $form['type_settings'] = [
- $workflow->get('type') => $workflow->getTypePlugin()->buildTransitionConfigurationForm($form_state, $workflow),
- '#tree' => TRUE,
- ];
+ if ($workflow_type->hasFormClass(TransitionInterface::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, TransitionInterface::PLUGIN_FORM_KEY)
+ ->buildConfigurationForm($form['type_settings'], $subform_state);
+ }
return $form;
}
@@ -105,20 +142,16 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
$entity->getTypePlugin()->addTransition($values['id'], $values['label'], array_filter($values['from']), $values['to']);
- if (isset($values['type_settings'])) {
- $configuration = $entity->getTypePlugin()->getConfiguration();
- $configuration['transitions'][$values['id']] += $values['type_settings'][$entity->getTypePlugin()->getPluginId()];
- $entity->set('type_settings', $configuration);
- }
}
-
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->getEntity();
+ $workflow_type = $workflow->getTypePlugin();
+
$values = $form_state->getValues();
foreach (array_filter($values['from']) as $from_state_id) {
if ($workflow->getTypePlugin()->hasTransitionFromStateToState($from_state_id, $values['to'])) {
@@ -128,6 +161,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
]));
}
}
+
+ if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
+ ->validateConfigurationForm($form['type_settings'], $subform_state);
+ }
}
/**
@@ -136,6 +176,17 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
+ $workflow_type = $workflow->getTypePlugin();
+ $transition = $workflow_type->getTransition($form_state->getValue('id'));
+
+ if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $subform_state->set('transition', $transition);
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
+ ->submitConfigurationForm($form['type_settings'], $subform_state);
+ }
+
$workflow->save();
drupal_set_message($this->t('Created %label transition.', [
'%label' => $form_state->getValue('label'),
diff --git a/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php
index f776e35c3d28cf11980ee5d91ecf693e510862a9..1406025a72f7ef5ddab9ad169372d0fd249ba437 100644
--- a/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php
+++ b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php
@@ -5,8 +5,12 @@
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\State;
+use Drupal\workflows\TransitionInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class WorkflowTransitionEditForm.
@@ -20,6 +24,32 @@ class WorkflowTransitionEditForm extends EntityForm {
*/
protected $transitionId;
+ /**
+ * 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}
*/
@@ -43,7 +73,9 @@ public function form(array $form, FormStateInterface $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('Label'),
@@ -78,10 +110,16 @@ public function form(array $form, FormStateInterface $form_state) {
];
// Add additional form fields from the workflow type plugin.
- $form['type_settings'] = [
- $workflow->get('type') => $workflow->getTypePlugin()->buildTransitionConfigurationForm($form_state, $workflow, $transition),
- '#tree' => TRUE,
- ];
+ 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;
}
@@ -92,11 +130,14 @@ public function form(array $form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->getEntity();
+ $workflow_type = $workflow->getTypePlugin();
+ $transition = $workflow_type->getTransition($this->transitionId);
+
$values = $form_state->getValues();
foreach (array_filter($values['from']) as $from_state_id) {
- if ($workflow->getTypePlugin()->hasTransitionFromStateToState($from_state_id, $values['to'])) {
- $transition = $workflow->getTypePlugin()->getTransitionFromStateToState($from_state_id, $values['to']);
- if ($transition->id() !== $values['id']) {
+ if ($workflow_type->hasTransitionFromStateToState($from_state_id, $values['to'])) {
+ $existing_transition = $workflow_type->getTransitionFromStateToState($from_state_id, $values['to']);
+ if ($existing_transition->id() !== $values['id']) {
$form_state->setErrorByName('from][' . $from_state_id, $this->t('The transition from %from to %to already exists.', [
'%from' => $workflow->getTypePlugin()->getState($from_state_id)->label(),
'%to' => $workflow->getTypePlugin()->getState($values['to'])->label(),
@@ -104,6 +145,14 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
}
}
+
+ if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $subform_state->set('transition', $transition);
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
+ ->validateConfigurationForm($form['type_settings'], $subform_state);
+ }
}
/**
@@ -128,11 +177,6 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
$form_state->set('created_transition', FALSE);
$entity->getTypePlugin()->setTransitionLabel($values['id'], $values['label']);
$entity->getTypePlugin()->setTransitionFromStates($values['id'], array_filter($values['from']));
- if (isset($values['type_settings'])) {
- $configuration = $entity->getTypePlugin()->getConfiguration();
- $configuration['transitions'][$values['id']] += $values['type_settings'][$entity->getTypePlugin()->getPluginId()];
- $entity->set('type_settings', $configuration);
- }
}
/**
@@ -141,6 +185,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();
+ $transition = $workflow_type->getTransition($this->transitionId);
+
+ if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
+ $subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
+ $subform_state->set('transition', $transition);
+ $this->pluginFormFactory
+ ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
+ ->submitConfigurationForm($form['type_settings'], $subform_state);
+ }
+
$workflow->save();
drupal_set_message($this->t('Saved %label transition.', [
'%label' => $workflow->getTypePlugin()->getTransition($this->transitionId)->label(),
diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
index 96faa62de2ec756a03abe536f8e8e8fa6958e69d..b7e18d9dd972460a402c4a7ee4576320995142b1 100644
--- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
+++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
@@ -4,12 +4,11 @@
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Access\AccessResult;
-use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Plugin\PluginWithFormsTrait;
use Drupal\Core\Session\AccountInterface;
use Drupal\workflows\State;
use Drupal\workflows\StateInterface;
use Drupal\workflows\Transition;
-use Drupal\workflows\TransitionInterface;
use Drupal\workflows\WorkflowInterface;
use Drupal\workflows\WorkflowTypeInterface;
@@ -24,6 +23,8 @@
*/
abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterface {
+ use PluginWithFormsTrait;
+
/**
* A regex for matching a valid state/transition machine name.
*/
@@ -68,20 +69,6 @@ public function workflowStateHasData(WorkflowInterface $workflow, StateInterface
return FALSE;
}
- /**
- * {@inheritdoc}
- */
- public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) {
- return [];
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) {
- return [];
- }
-
/**
* {@inheritdoc}
*/
diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeConfigureFormBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeConfigureFormBase.php
new file mode 100644
index 0000000000000000000000000000000000000000..535330498851585f8d3e7120406f30256236aea6
--- /dev/null
+++ b/core/modules/workflows/src/Plugin/WorkflowTypeConfigureFormBase.php
@@ -0,0 +1,38 @@
+workflowType = $plugin;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
+ }
+
+}
diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php
deleted file mode 100644
index 942c2d6ef41155c7cbbb5d224eb7d27685d23a84..0000000000000000000000000000000000000000
--- a/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php
+++ /dev/null
@@ -1,30 +0,0 @@
-workflowType = $plugin;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ $state = $form_state->get('state');
+ $configuration = $this->workflowType->getConfiguration();
+ $configuration['states'][$state->id()] = $values + $configuration['states'][$state->id()];
+ $this->workflowType->setConfiguration($configuration);
+ }
+
+}
diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeTransitionFormBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeTransitionFormBase.php
new file mode 100644
index 0000000000000000000000000000000000000000..e1d619644c108d9eb24b9982d2f321ccde8e7c47
--- /dev/null
+++ b/core/modules/workflows/src/Plugin/WorkflowTypeTransitionFormBase.php
@@ -0,0 +1,49 @@
+workflowType = $plugin;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ $transition = $form_state->get('transition');
+ $configuration = $this->workflowType->getConfiguration();
+ $configuration['transitions'][$transition->id()] = $values + $configuration['transitions'][$transition->id()];
+ $this->workflowType->setConfiguration($configuration);
+ }
+
+}
diff --git a/core/modules/workflows/src/StateInterface.php b/core/modules/workflows/src/StateInterface.php
index 27a1dd27173ae1f428d789ba2defe6098f9a738c..5a5442bb1d6c53d1a71e4905471be7c409828cab 100644
--- a/core/modules/workflows/src/StateInterface.php
+++ b/core/modules/workflows/src/StateInterface.php
@@ -11,6 +11,11 @@
*/
interface StateInterface {
+ /**
+ * The key of the state plugin form.
+ */
+ const PLUGIN_FORM_KEY = 'state';
+
/**
* Gets the state's ID.
*
diff --git a/core/modules/workflows/src/TransitionInterface.php b/core/modules/workflows/src/TransitionInterface.php
index c178b22da1e2c6d6c4c33f979fbace7d3d6ba5f2..14f6d1487c6fc071914300a951cd60d5bda4131e 100644
--- a/core/modules/workflows/src/TransitionInterface.php
+++ b/core/modules/workflows/src/TransitionInterface.php
@@ -11,6 +11,11 @@
*/
interface TransitionInterface {
+ /**
+ * The key of the transition plugin form.
+ */
+ const PLUGIN_FORM_KEY = 'transition';
+
/**
* Gets the transition's ID.
*
diff --git a/core/modules/workflows/src/WorkflowTypeFormInterface.php b/core/modules/workflows/src/WorkflowTypeFormInterface.php
deleted file mode 100644
index 7da4bd9fb3a3bc66e6f0f3059e88bddb3cfa1e91..0000000000000000000000000000000000000000
--- a/core/modules/workflows/src/WorkflowTypeFormInterface.php
+++ /dev/null
@@ -1,16 +0,0 @@
-workflowType->getConfiguration();
+ $form['example_setting'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Example global workflow setting'),
+ '#description' => $this->t('Extra information added to the workflow'),
+ '#default_value' => $type_configuration['example_setting'],
+ ];
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+ $type_configuration = $this->workflowType->getConfiguration();
+ $type_configuration['example_setting'] = $form_state->getValue('example_setting');
+ $this->workflowType->setConfiguration($type_configuration);
+ }
+
+}
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php
new file mode 100644
index 0000000000000000000000000000000000000000..679b314d19696252fb496658bd9b15d29c4f51d2
--- /dev/null
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php
@@ -0,0 +1,30 @@
+get('state');
+ $configuration = $this->workflowType->getConfiguration();
+ $form['extra'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Extra'),
+ '#description' => $this->t('Extra information added to state'),
+ '#default_value' => isset($configuration['states'][$state->id()]['extra']) ? $configuration['states'][$state->id()]['extra'] : '',
+ ];
+ return $form;
+ }
+
+}
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php
new file mode 100644
index 0000000000000000000000000000000000000000..45e15139b9d08507382fe20203ddbdae16f719e5
--- /dev/null
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php
@@ -0,0 +1,30 @@
+get('transition');
+ $configuration = $this->workflowType->getConfiguration();
+ $form['extra'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Extra'),
+ '#description' => $this->t('Extra information added to transition'),
+ '#default_value' => isset($configuration['transitions'][$transition->id()]['extra']) ? $configuration['transitions'][$transition->id()]['extra'] : '',
+ ];
+ return $form;
+ }
+
+}
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php
index 3e8b40274ab1534b85039204a1be60b5f5a07bf4..30b175c32e1804533ead26cad9c675d350de7954 100644
--- a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php
@@ -2,12 +2,8 @@
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
-use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
-use Drupal\workflows\Plugin\WorkflowTypeFormBase;
-use Drupal\workflows\StateInterface;
-use Drupal\workflows\TransitionInterface;
-use Drupal\workflows\WorkflowInterface;
+use Drupal\workflows\Plugin\WorkflowTypeBase;
/**
* Test workflow type.
@@ -15,40 +11,17 @@
* @WorkflowType(
* id = "workflow_type_complex_test",
* label = @Translation("Workflow Type Complex Test"),
+ * forms = {
+ * "configure" = "\Drupal\workflow_type_test\Form\ComplexTestTypeConfigureForm",
+ * "state" = "\Drupal\workflow_type_test\Form\ComplexTestTypeStateForm",
+ * "transition" = "\Drupal\workflow_type_test\Form\ComplexTestTypeTransitionForm",
+ * }
* )
*/
-class ComplexTestType extends WorkflowTypeFormBase {
+class ComplexTestType extends WorkflowTypeBase {
use StringTranslationTrait;
- /**
- * {@inheritdoc}
- */
- public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) {
- $form = [];
- $form['extra'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Extra'),
- '#description' => $this->t('Extra information added to state'),
- '#default_value' => isset($this->configuration['states'][$state->id()]['extra']) ? $this->configuration['states'][$state->id()]['extra'] : '',
- ];
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) {
- $form = [];
- $form['extra'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Extra'),
- '#description' => $this->t('Extra information added to transition'),
- '#default_value' => isset($this->configuration['transitions'][$transition->id()]['extra']) ? $this->configuration['transitions'][$transition->id()]['extra'] : '',
- ];
- return $form;
- }
-
/**
* {@inheritdoc}
*/
@@ -67,24 +40,4 @@ public function defaultConfiguration() {
];
}
- /**
- * {@inheritdoc}
- */
- public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
- $form['example_setting'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Example global workflow setting'),
- '#description' => $this->t('Extra information added to the workflow'),
- '#default_value' => $this->configuration['example_setting'],
- ];
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
- $this->configuration['example_setting'] = $form_state->getValue('example_setting');
- }
-
}