setTransitionLabel example

// Passing in no IDs returns all transitions.     $this->assertEquals(['a_b', 'a_a']array_keys($workflow->getTypePlugin()->getTransitions()));

    // The order of states is by weight.     $workflow->getTypePlugin()->setTransitionWeight('a_a', -1);
    $this->assertEquals(['a_a', 'a_b']array_keys($workflow->getTypePlugin()->getTransitions()));

    // If all weights are equal it will fallback to labels.     $workflow->getTypePlugin()->setTransitionWeight('a_a', 0);
    $this->assertEquals(['a_a', 'a_b']array_keys($workflow->getTypePlugin()->getTransitions()));
    $workflow->getTypePlugin()->setTransitionLabel('a_b', 'A B');
    $this->assertEquals(['a_b', 'a_a']array_keys($workflow->getTypePlugin()->getTransitions()));

    // You can limit the states returned by passing in states IDs.     $this->assertEquals(['a_a']array_keys($workflow->getTypePlugin()->getTransitions(['a_a'])));

    // An empty array does not load all states.     $this->assertSame([]$workflow->getTypePlugin()->getTransitions([]));
  }

  /** * @covers ::getTransition */

  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();
    $form_state->set('created_transition', FALSE);
    $entity->getTypePlugin()->setTransitionLabel($values['id']$values['label']);
    $entity->getTypePlugin()->setTransitionFromStates($values['id']array_filter($values['from']));
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $workflow_type = $workflow->getTypePlugin();
    $transition = $workflow_type->getTransition($this->transitionId);

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