hasTransition example

// By default states are ordered in the order added.     $workflow
      ->getTypePlugin()
      ->addState('draft', 'Draft')
      ->addState('published', 'Published');

    $this->assertFalse($workflow->getTypePlugin()->getState('draft')->canTransitionTo('published'));
    $workflow->getTypePlugin()->addTransition('publish', 'Publish', ['draft'], 'published');
    $this->assertTrue($workflow->getTypePlugin()->getState('draft')->canTransitionTo('published'));
    $this->assertEquals(0, $workflow->getTypePlugin()->getTransition('publish')->weight());
    $this->assertTrue($workflow->getTypePlugin()->hasTransition('publish'));
    $this->assertFalse($workflow->getTypePlugin()->hasTransition('draft'));

    $workflow->getTypePlugin()->addTransition('save_publish', 'Save', ['published'], 'published');
    $this->assertEquals(1, $workflow->getTypePlugin()->getTransition('save_publish')->weight());
  }

  /** * @covers ::addTransition */
  public function testAddTransitionDuplicateException() {
    $this->expectException(\InvalidArgumentException::class);
    
        $this->setTransitionFromStates($transition_id$transition['from']);
      }
    }
    unset($this->configuration['states'][$state_id]);
    return $this;
  }

  /** * {@inheritdoc} */
  public function addTransition($transition_id$label, array $from_state_ids$to_state_id) {
    if ($this->hasTransition($transition_id)) {
      throw new \InvalidArgumentException("The transition '$transition_id' already exists in workflow.");
    }
    if (preg_match(static::VALID_ID_REGEX, $transition_id)) {
      throw new \InvalidArgumentException("The transition ID '$transition_id' must contain only lowercase letters, numbers, and underscores.");
    }

    if (!$this->hasState($to_state_id)) {
      throw new \InvalidArgumentException("The state '$to_state_id' does not exist in workflow.");
    }
    $this->configuration['transitions'][$transition_id] = [
      'label' => $label,
      

  public function exists($transition_id) {
    /** @var \Drupal\workflows\WorkflowInterface $original_workflow */
    $original_workflow = \Drupal::entityTypeManager()->getStorage('workflow')->loadUnchanged($this->getEntity()->id());
    return $original_workflow->getTypePlugin()->hasTransition($transition_id);
  }

  /** * 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. */
'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'));
  }

}
$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');
  }

  /** * Tests the workflow configuration form. */
  public function testWorkflowConfigurationForm() {
    $workflow = Workflow::create(['id' => 'test', 'type' => 'workflow_type_complex_test', 'label' => 'Test']);
    $workflow
      ->getTypePlugin()
      
Home | Imprint | This part of the site doesn't use cookies.