Chris@0: workflow = $workflow; Chris@0: $this->id = $id; Chris@0: $this->label = $label; Chris@0: $this->weight = $weight; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function id() { Chris@0: return $this->id; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function label() { Chris@0: return $this->label; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function weight() { Chris@0: return $this->weight; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function canTransitionTo($to_state_id) { Chris@0: return $this->workflow->hasTransitionFromStateToState($this->id, $to_state_id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTransitionTo($to_state_id) { Chris@0: if (!$this->canTransitionTo($to_state_id)) { Chris@0: throw new \InvalidArgumentException("Can not transition to '$to_state_id' state"); Chris@0: } Chris@0: return $this->workflow->getTransitionFromStateToState($this->id(), $to_state_id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTransitions() { Chris@0: return $this->workflow->getTransitionsForState($this->id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper method to convert a State value object to a label. Chris@0: * Chris@0: * @param \Drupal\workflows\StateInterface $state Chris@0: * Chris@0: * @return string Chris@0: * The label of the state. Chris@0: */ Chris@0: public static function labelCallback(StateInterface $state) { Chris@0: return $state->label(); Chris@0: } Chris@0: Chris@0: }