3 namespace Drupal\workflows;
6 * A value object representing a workflow state.
8 class State implements StateInterface {
11 * The workflow the state is attached to.
13 * @var \Drupal\workflows\WorkflowInterface
41 * @param \Drupal\workflows\WorkflowInterface $workflow
42 * The workflow the state is attached to.
45 * @param string $label
50 public function __construct(WorkflowTypeInterface $workflow, $id, $label, $weight = 0) {
51 $this->workflow = $workflow;
53 $this->label = $label;
54 $this->weight = $weight;
60 public function id() {
67 public function label() {
74 public function weight() {
81 public function canTransitionTo($to_state_id) {
82 return $this->workflow->hasTransitionFromStateToState($this->id, $to_state_id);
88 public function getTransitionTo($to_state_id) {
89 if (!$this->canTransitionTo($to_state_id)) {
90 throw new \InvalidArgumentException("Can not transition to '$to_state_id' state");
92 return $this->workflow->getTransitionFromStateToState($this->id(), $to_state_id);
98 public function getTransitions() {
99 return $this->workflow->getTransitionsForState($this->id);
103 * Helper method to convert a State value object to a label.
105 * @param \Drupal\workflows\StateInterface $state
108 * The label of the state.
110 public static function labelCallback(StateInterface $state) {
111 return $state->label();