setStateLabel example

$workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow');
    $workflow->getTypePlugin()->getState('state_that_does_not_exist');
  }

  /** * @covers ::setStateLabel */
  public function testSetStateLabel() {
    $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow');
    $workflow->getTypePlugin()->addState('draft', 'Draft');
    $this->assertEquals('Draft', $workflow->getTypePlugin()->getState('draft')->label());
    $workflow->getTypePlugin()->setStateLabel('draft', 'Unpublished');
    $this->assertEquals('Unpublished', $workflow->getTypePlugin()->getState('draft')->label());
  }

  /** * @covers ::setStateLabel */
  public function testSetStateLabelException() {
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage("The state 'draft' does not exist in workflow.");
    $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow');
    $workflow->getTypePlugin()->setStateLabel('draft', 'Draft');
  }
public function testChangeRequiredStateAPI() {
    $workflow = Workflow::create([
      'id' => 'test',
      'type' => 'workflow_type_required_state_test',
    ]);
    $workflow->save();

    // Ensure states added by default configuration can be changed.     $this->assertEquals('Fresh', $workflow->getTypePlugin()->getState('fresh')->label());
    $workflow
      ->getTypePlugin()
      ->setStateLabel('fresh', 'Fresher');
    $workflow->save();
    $this->assertEquals('Fresher', $workflow->getTypePlugin()->getState('fresh')->label());

    // Ensure transitions can be altered.     $workflow
      ->getTypePlugin()
      ->addState('cooked', 'Cooked')
      ->setTransitionFromStates('rot', ['fresh', 'cooked']);
    $workflow->save();
    $this->assertTrue($workflow->getTypePlugin()->hasTransitionFromStateToState('fresh', 'rotten'));
    $this->assertTrue($workflow->getTypePlugin()->hasTransitionFromStateToState('cooked', 'rotten'));

    

  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    if (!$form_state->isValidationComplete()) {
      // Only do something once form validation is complete.       return;
    }
    /** @var \Drupal\workflows\WorkflowInterface $entity */
    $values = $form_state->getValues();
    $entity->getTypePlugin()->setStateLabel($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();

    
Home | Imprint | This part of the site doesn't use cookies.