3 namespace Drupal\workflows;
6 * A value object representing a workflow state.
9 * The workflow system is currently experimental and should only be leveraged
10 * by experimental modules and development releases of contributed modules.
12 class State implements StateInterface {
15 * The workflow the state is attached to.
17 * @var \Drupal\workflows\WorkflowInterface
45 * @param \Drupal\workflows\WorkflowInterface $workflow
46 * The workflow the state is attached to.
49 * @param string $label
54 public function __construct(WorkflowInterface $workflow, $id, $label, $weight = 0) {
55 $this->workflow = $workflow;
57 $this->label = $label;
58 $this->weight = $weight;
64 public function id() {
71 public function label() {
78 public function weight() {
85 public function canTransitionTo($to_state_id) {
86 return $this->workflow->hasTransitionFromStateToState($this->id, $to_state_id);
92 public function getTransitionTo($to_state_id) {
93 if (!$this->canTransitionTo($to_state_id)) {
94 throw new \InvalidArgumentException("Can not transition to '$to_state_id' state");
96 return $this->workflow->getTransitionFromStateToState($this->id(), $to_state_id);
102 public function getTransitions() {
103 return $this->workflow->getTransitionsForState($this->id);
107 * Helper method to convert a list of states to labels
109 * @param \Drupal\workflows\StateInterface $state
112 * The label of the state.
114 public static function labelCallback(StateInterface $state) {
115 return $state->label();