Further changes for the Use cases on the live site.
[yaffs-website] / web / core / modules / workflows / src / Transition.php
1 <?php
2
3 namespace Drupal\workflows;
4
5 /**
6  * A transition value object that describes the transition between states.
7  *
8  * @internal
9  *   The workflow system is currently experimental and should only be leveraged
10  *   by experimental modules and development releases of contributed modules.
11  */
12 class Transition implements TransitionInterface {
13
14   /**
15    * The workflow that this transition is attached to.
16    *
17    * @var \Drupal\workflows\WorkflowInterface
18    */
19   protected $workflow;
20
21   /**
22    * The transition's ID.
23    *
24    * @var string
25    */
26   protected $id;
27
28   /**
29    * The transition's label.
30    *
31    * @var string
32    */
33   protected $label;
34
35   /**
36    * The transition's from state IDs.
37    *
38    * @var string[]
39    */
40   protected $fromStateIds;
41
42   /**
43    * The transition's to state ID.
44    *
45    * @var string
46    */
47   protected $toStateId;
48
49   /**
50    * The transition's weight.
51    *
52    * @var int
53    */
54   protected $weight;
55
56   /**
57    * Transition constructor.
58    *
59    * @param \Drupal\workflows\WorkflowInterface $workflow
60    *   The workflow the state is attached to.
61    * @param string $id
62    *   The transition's ID.
63    * @param string $label
64    *   The transition's label.
65    * @param array $from_state_ids
66    *   A list of from state IDs.
67    * @param string $to_state_id
68    *   The to state ID.
69    * @param int $weight
70    *   (optional) The transition's weight. Defaults to 0.
71    */
72   public function __construct(WorkflowInterface $workflow, $id, $label, array $from_state_ids, $to_state_id, $weight = 0) {
73     $this->workflow = $workflow;
74     $this->id = $id;
75     $this->label = $label;
76     $this->fromStateIds = $from_state_ids;
77     $this->toStateId = $to_state_id;
78     $this->weight = $weight;
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   public function id() {
85     return $this->id;
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function label() {
92     return $this->label;
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   public function from() {
99     return $this->workflow->getStates($this->fromStateIds);
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   public function to() {
106     return $this->workflow->getState($this->toStateId);
107   }
108
109   /**
110    * {@inheritdoc}
111    */
112   public function weight() {
113     return $this->weight;
114   }
115
116 }