Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\content_moderation;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\workflows\StateInterface;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * A value object representing a workflow state for content moderation.
|
Chris@0
|
9 */
|
Chris@0
|
10 class ContentModerationState implements StateInterface {
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * The vanilla state object from the Workflow module.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @var \Drupal\workflows\StateInterface
|
Chris@0
|
16 */
|
Chris@0
|
17 protected $state;
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * If entities should be published if in this state.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @var bool
|
Chris@0
|
23 */
|
Chris@0
|
24 protected $published;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * If entities should be the default revision if in this state.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @var bool
|
Chris@0
|
30 */
|
Chris@0
|
31 protected $defaultRevision;
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * ContentModerationState constructor.
|
Chris@0
|
35 *
|
Chris@0
|
36 * Decorates state objects to add methods to determine if an entity should be
|
Chris@0
|
37 * published or made the default revision.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @param \Drupal\workflows\StateInterface $state
|
Chris@0
|
40 * The vanilla state object from the Workflow module.
|
Chris@0
|
41 * @param bool $published
|
Chris@0
|
42 * (optional) TRUE if entities should be published if in this state, FALSE
|
Chris@0
|
43 * if not. Defaults to FALSE.
|
Chris@0
|
44 * @param bool $default_revision
|
Chris@0
|
45 * (optional) TRUE if entities should be the default revision if in this
|
Chris@0
|
46 * state, FALSE if not. Defaults to FALSE.
|
Chris@0
|
47 */
|
Chris@0
|
48 public function __construct(StateInterface $state, $published = FALSE, $default_revision = FALSE) {
|
Chris@0
|
49 $this->state = $state;
|
Chris@0
|
50 $this->published = $published;
|
Chris@0
|
51 $this->defaultRevision = $default_revision;
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Determines if entities should be published if in this state.
|
Chris@0
|
56 *
|
Chris@0
|
57 * @return bool
|
Chris@0
|
58 */
|
Chris@0
|
59 public function isPublishedState() {
|
Chris@0
|
60 return $this->published;
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 /**
|
Chris@0
|
64 * Determines if entities should be the default revision if in this state.
|
Chris@0
|
65 *
|
Chris@0
|
66 * @return bool
|
Chris@0
|
67 */
|
Chris@0
|
68 public function isDefaultRevisionState() {
|
Chris@0
|
69 return $this->defaultRevision;
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 /**
|
Chris@0
|
73 * {@inheritdoc}
|
Chris@0
|
74 */
|
Chris@0
|
75 public function id() {
|
Chris@0
|
76 return $this->state->id();
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * {@inheritdoc}
|
Chris@0
|
81 */
|
Chris@0
|
82 public function label() {
|
Chris@0
|
83 return $this->state->label();
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * {@inheritdoc}
|
Chris@0
|
88 */
|
Chris@0
|
89 public function weight() {
|
Chris@0
|
90 return $this->state->weight();
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 /**
|
Chris@0
|
94 * {@inheritdoc}
|
Chris@0
|
95 */
|
Chris@0
|
96 public function canTransitionTo($to_state_id) {
|
Chris@0
|
97 return $this->state->canTransitionTo($to_state_id);
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * {@inheritdoc}
|
Chris@0
|
102 */
|
Chris@0
|
103 public function getTransitionTo($to_state_id) {
|
Chris@0
|
104 return $this->state->getTransitionTo($to_state_id);
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 /**
|
Chris@0
|
108 * {@inheritdoc}
|
Chris@0
|
109 */
|
Chris@0
|
110 public function getTransitions() {
|
Chris@0
|
111 return $this->state->getTransitions();
|
Chris@0
|
112 }
|
Chris@0
|
113
|
Chris@0
|
114 }
|