diff -u b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php --- b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php +++ b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php @@ -120,6 +120,7 @@ $form_state->set('created_transition', FALSE); $entity->setTransitionLabel($values['id'], $values['label']); $entity->setTransitionFromStates($values['id'], array_filter($values['from'])); + $entity->setTransitionToState($values['id'], $values['to']); if (isset($values['type_settings'])) { $configuration = $entity->getTypePlugin()->getConfiguration(); $configuration['transitions'][$values['id']] = $values['type_settings'][$entity->getTypePlugin()->getPluginId()]; only in patch2: unchanged: --- a/core/modules/workflows/src/Entity/Workflow.php +++ b/core/modules/workflows/src/Entity/Workflow.php @@ -427,6 +427,36 @@ public function setTransitionFromStates($transition_id, array $from_state_ids) { /** * {@inheritdoc} */ + public function setTransitionToState($transition_id, $to_state_id) { + if (!isset($this->transitions[$transition_id])) { + throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow '{$this->id()}'"); + } + + // Ensure that the states exist. + if (!$this->hasState($to_state_id)) { + throw new \InvalidArgumentException("The state '$to_state_id' does not exist in workflow '{$this->id()}'"); + } + + if ($this->transitions[$transition_id]['from']) { + foreach ($this->transitions[$transition_id]['from'] as $from_state_id) { + if ($this->hasTransitionFromStateToState($from_state_id, $to_state_id)) { + $transition = $this->getTransitionFromStateToState($from_state_id, $to_state_id); + if ($transition_id !== $transition->id()) { + throw new \InvalidArgumentException("The '{$transition->id()}' transition already allows '$from_state_id' to '$to_state_id' transitions in workflow '{$this->id()}'"); + } + } + } + } + + // Update the transitions. + $this->transitions[$transition_id]['to'] = $to_state_id; + + return $this; + } + + /** + * {@inheritdoc} + */ public function deleteTransition($transition_id) { if (isset($this->transitions[$transition_id])) { unset($this->transitions[$transition_id]); only in patch2: unchanged: --- a/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php +++ b/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php @@ -155,6 +155,34 @@ public function testWorkflowCreation() { $workflow = $workflow_storage->loadUnchanged('test'); $this->assertFalse($workflow->hasTransitionFromStateToState('published', 'published'), 'Cannot transition from published to published'); + // Create a state to test changing the transition 'to' value. + $this->drupalGet('admin/config/workflow/workflows/manage/test'); + $this->clickLink('Add a new state'); + $this->submitForm(['label' => 'ToTestState', 'id' => 'toteststate'], 'Save'); + $this->assertSession()->pageTextContains('Created ToTestState state.'); + // Create a new transition to test changing the transition 'to' value. + $this->drupalGet('admin/config/workflow/workflows/manage/test'); + $this->clickLink('Add a new transition'); + $this->submitForm(['id' => 'totesttransition', 'label' => 'ToTestTransition', 'from[toteststate]' => 'toteststate', 'to' => 'draft'], 'Save'); + $this->assertSession()->pageTextContains('Created ToTestTransition transition.'); + $workflow = $workflow_storage->loadUnchanged('test'); + $this->assertTrue($workflow->getState('toteststate')->canTransitionTo('draft'), 'Can transition from toteststate to draft'); + // Edit the new transition to test changing the transition 'to' value. + $this->drupalGet('admin/config/workflow/workflows/manage/test/transition/totesttransition'); + $this->assertSession()->pageTextContains('ToTestTransition'); + $this->submitForm(['from[toteststate]' => 'toteststate', 'to' => 'published'], 'Save'); + $workflow = $workflow_storage->loadUnchanged('test'); + $this->assertTrue($workflow->getState('toteststate')->canTransitionTo('published'), 'Can transition from toteststate to published'); + $this->assertFalse($workflow->getState('toteststate')->canTransitionTo('draft'), 'Can no longer transition from toteststate to draft'); + // Delete transition use in test changing the transition 'to' value. + $this->drupalGet('admin/config/workflow/workflows/manage/test/transition/totesttransition'); + $this->clickLink('Delete'); + $this->submitForm([], 'Delete'); + // Delete state use in test changing the transition 'to' value. + $this->drupalGet('admin/config/workflow/workflows/manage/test/state/toteststate'); + $this->clickLink('Delete'); + $this->submitForm([], 'Delete'); + // Try creating a duplicate state. $this->drupalGet('admin/config/workflow/workflows/manage/test'); $this->clickLink('Add a new state');