deleteTransition example


  public function deleteState($state_id) {
    if (!$this->hasState($state_id)) {
      throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.");
    }
    if (count($this->configuration['states']) === 1) {
      throw new \InvalidArgumentException("The state '$state_id' can not be deleted from workflow as it is the only state.");
    }

    foreach ($this->configuration['transitions'] as $transition_id => $transition) {
      if ($transition['to'] === $state_id) {
        $this->deleteTransition($transition_id);
        continue;
      }
      $from_key = array_search($state_id$transition['from'], TRUE);
      if ($from_key !== FALSE) {
        // Remove state from the from array.         unset($transition['from'][$from_key]);
        if (empty($transition['from'])) {
          // There are no more 'from' entries, remove the transition.           $this->deleteTransition($transition_id);
          continue;
        }
        

    $this->workflow = $workflow;
    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->workflow
      ->getTypePlugin()
      ->deleteTransition($this->transition->id());
    $this->workflow->save();

    $this->messenger()->addStatus($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}
$this->assertSame([
      'cooked',
      'fresh',
      'rotten',
    ]array_keys($workflow->getTypePlugin()->getConfiguration()['states']));
    $this->assertSame([
      'cook',
      'rot',
    ]array_keys($workflow->getTypePlugin()->getConfiguration()['transitions']));

    // Ensure that transitions can be deleted.     $workflow->getTypePlugin()->deleteTransition('rot');
    $workflow->save();
    $this->assertFalse($workflow->getTypePlugin()->hasTransition('rot'));
  }

}

  public function testCanTransitionTo() {
    $workflow_type = new TestType([], '', []);
    $workflow_type
      ->addState('draft', 'Draft')
      ->addState('published', 'Published')
      ->addTransition('publish', 'Publish', ['draft'], 'published');
    $state = $workflow_type->getState('draft');
    $this->assertTrue($state->canTransitionTo('published'));
    $this->assertFalse($state->canTransitionTo('some_other_state'));

    $workflow_type->deleteTransition('publish');
    $this->assertFalse($state->canTransitionTo('published'));
  }

  /** * @covers ::getTransitionTo */
  public function testGetTransitionTo() {
    $workflow_type = new TestType([], '', []);
    $workflow_type
      ->addState('draft', 'Draft')
      ->addState('published', 'Published')
      
/** * @covers ::deleteTransition */
  public function testDeleteTransition() {
    $workflow_type = new TestType([], '', []);
    $workflow_type
      ->addState('draft', 'Draft')
      ->addState('published', 'Published')
      ->addTransition('create_new_draft', 'Create new draft', ['draft'], 'draft')
      ->addTransition('publish', 'Publish', ['draft'], 'published');
    $this->assertTrue($workflow_type->getState('draft')->canTransitionTo('published'));
    $workflow_type->deleteTransition('publish');
    $this->assertFalse($workflow_type->getState('draft')->canTransitionTo('published'));
    $this->assertTrue($workflow_type->getState('draft')->canTransitionTo('draft'));
  }

  /** * @covers ::deleteTransition */
  public function testDeleteTransitionException() {
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage("The transition 'draft-published' does not exist in workflow.");
    $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow');
    
Home | Imprint | This part of the site doesn't use cookies.