summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/ContentModerationState.php
blob: 34262eb59f6f0a251cd8a53b0fa2fdf36f775848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php

namespace Drupal\content_moderation;

use Drupal\workflows\StateInterface;

/**
 * A value object representing a workflow state for content moderation.
 */
class ContentModerationState implements StateInterface {

  /**
   * The vanilla state object from the Workflow module.
   *
   * @var \Drupal\workflows\StateInterface
   */
  protected $state;

  /**
   * If entities should be published if in this state.
   *
   * @var bool
   */
  protected $published;

  /**
   * If entities should be the default revision if in this state.
   *
   * @var bool
   */
  protected $defaultRevision;

  /**
   * ContentModerationState constructor.
   *
   * Decorates state objects to add methods to determine if an entity should be
   * published or made the default revision.
   *
   * @param \Drupal\workflows\StateInterface $state
   *   The vanilla state object from the Workflow module.
   * @param bool $published
   *   (optional) TRUE if entities should be published if in this state, FALSE
   *   if not. Defaults to FALSE.
   * @param bool $default_revision
   *   (optional) TRUE if entities should be the default revision if in this
   *   state, FALSE if not. Defaults to FALSE.
   */
  public function __construct(StateInterface $state, $published = FALSE, $default_revision = FALSE) {
    $this->state = $state;
    $this->published = $published;
    $this->defaultRevision = $default_revision;
  }

  /**
   * Determines if entities should be published if in this state.
   *
   * @return bool
   */
  public function isPublishedState() {
    return $this->published;
  }

  /**
   * Determines if entities should be the default revision if in this state.
   *
   * @return bool
   */
  public function isDefaultRevisionState() {
    return $this->defaultRevision;
  }

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this->state->id();
  }

  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->state->label();
  }

  /**
   * {@inheritdoc}
   */
  public function weight() {
    return $this->state->weight();
  }

  /**
   * {@inheritdoc}
   */
  public function canTransitionTo($to_state_id) {
    return $this->state->canTransitionTo($to_state_id);
  }

  /**
   * {@inheritdoc}
   */
  public function getTransitionTo($to_state_id) {
    return $this->state->getTransitionTo($to_state_id);
  }

  /**
   * {@inheritdoc}
   */
  public function getTransitions() {
    return $this->state->getTransitions();
  }

}