/**
* {@inheritdoc}
*/ publicfunctionaddTransition($transition_id, $label, array $from_state_ids, $to_state_id){ if($this->hasTransition($transition_id)){ thrownew \InvalidArgumentException("The transition '$transition_id' already exists in workflow."); } if(preg_match(static::VALID_ID_REGEX, $transition_id)){ thrownew \InvalidArgumentException("The transition ID '$transition_id' must contain only lowercase letters, numbers, and underscores."); }
if(!$this->hasState($to_state_id)){ thrownew \InvalidArgumentException("The state '$to_state_id' does not exist in workflow."); } $this->configuration['transitions'][$transition_id] = [ 'label' => $label,
/**
* Copies top-level form values to entity properties.
*
* This form can only change values for a state, which is part of workflow.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity the current form should operate upon.
* @param array $form
* A nested array of form elements comprising the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
$this->assertNull($workflow_storage->loadUnchanged('test'), 'The test workflow has been deleted');
// Ensure that workflow types with default configuration are initialized
// correctly.
$this->drupalGet('admin/config/workflow/workflows'); $this->clickLink('Add workflow'); $this->submitForm(['label' => 'Test 2', 'id' => 'test2', 'workflow_type' => 'workflow_type_required_state_test'], 'Save'); $this->assertSession()->addressEquals('admin/config/workflow/workflows/manage/test2'); $workflow = $workflow_storage->loadUnchanged('test2'); $this->assertTrue($workflow->getTypePlugin()->hasState('fresh'), 'The workflow has the "fresh" state'); $this->assertTrue($workflow->getTypePlugin()->hasState('rotten'), 'The workflow has the "rotten" state'); $this->assertTrue($workflow->getTypePlugin()->hasTransition('rot'), 'The workflow has the "rot" transition'); $this->assertSession()->pageTextContains('Fresh'); $this->assertSession()->pageTextContains('Rotten'); }