summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/ContentModerationState.php
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-12-13 12:34:20 (GMT)
committerNathaniel Catchpole2016-12-13 12:34:20 (GMT)
commit0f139055718b608edfac1422e89667c7a7bf172a (patch)
tree6fa01b63b568cb50845320cc4721bc94e6b9ffab /core/modules/content_moderation/src/ContentModerationState.php
parente223ebe5f7c227f82c0c28f5538804501a746522 (diff)
Issue #2779647 by alexpott, Sam152, catch, scookie, yoroy, pericxc, timmillwood, tacituseu, jhedstrom, xjm, bojanz, tstoeckler: Add a workflow component, ui module, and implement it in content moderation
Diffstat (limited to 'core/modules/content_moderation/src/ContentModerationState.php')
-rw-r--r--core/modules/content_moderation/src/ContentModerationState.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/core/modules/content_moderation/src/ContentModerationState.php b/core/modules/content_moderation/src/ContentModerationState.php
new file mode 100644
index 0000000..34262eb
--- /dev/null
+++ b/core/modules/content_moderation/src/ContentModerationState.php
@@ -0,0 +1,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();
+ }
+
+}