You are here

public function State::getTransitionTo in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workflows/src/State.php \Drupal\workflows\State::getTransitionTo()

Gets the Transition object for the provided state ID.

Parameters

$to_state_id: The state to transition to.

Return value

\Drupal\workflows\TransitionInterface The Transition object for the provided state ID.

Throws

\InvalidArgumentException() Exception thrown when the provided state ID can not be transitioned to.

Overrides StateInterface::getTransitionTo

File

core/modules/workflows/src/State.php, line 88

Class

State
A value object representing a workflow state.

Namespace

Drupal\workflows

Code

public function getTransitionTo($to_state_id) {
  if (!$this
    ->canTransitionTo($to_state_id)) {
    throw new \InvalidArgumentException("Can not transition to '{$to_state_id}' state");
  }
  return $this->workflow
    ->getTransitionFromStateToState($this
    ->id(), $to_state_id);
}