summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/Entity
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/Entity
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/Entity')
-rw-r--r--core/modules/content_moderation/src/Entity/ContentModerationState.php13
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php31
-rw-r--r--core/modules/content_moderation/src/Entity/ModerationState.php102
-rw-r--r--core/modules/content_moderation/src/Entity/ModerationStateTransition.php114
4 files changed, 40 insertions, 220 deletions
diff --git a/core/modules/content_moderation/src/Entity/ContentModerationState.php b/core/modules/content_moderation/src/Entity/ContentModerationState.php
index 978408f..d60dad7 100644
--- a/core/modules/content_moderation/src/Entity/ContentModerationState.php
+++ b/core/modules/content_moderation/src/Entity/ContentModerationState.php
@@ -55,10 +55,17 @@ class ContentModerationState extends ContentEntityBase implements ContentModerat
->setTranslatable(TRUE)
->setRevisionable(TRUE);
- $fields['moderation_state'] = BaseFieldDefinition::create('entity_reference')
+ $fields['workflow'] = BaseFieldDefinition::create('entity_reference')
+ ->setLabel(t('Workflow'))
+ ->setDescription(t('The workflow the moderation state is in.'))
+ ->setSetting('target_type', 'workflow')
+ ->setRequired(TRUE)
+ ->setTranslatable(TRUE)
+ ->setRevisionable(TRUE);
+
+ $fields['moderation_state'] = BaseFieldDefinition::create('string')
->setLabel(t('Moderation state'))
->setDescription(t('The moderation state of the referenced content.'))
- ->setSetting('target_type', 'moderation_state')
->setRequired(TRUE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
@@ -155,7 +162,7 @@ class ContentModerationState extends ContentEntityBase implements ContentModerat
if ($related_entity instanceof TranslatableInterface) {
$related_entity = $related_entity->getTranslation($this->activeLangcode);
}
- $related_entity->moderation_state->target_id = $this->moderation_state->target_id;
+ $related_entity->moderation_state = $this->moderation_state;
return $related_entity->save();
}
diff --git a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
index 83de187..247d352 100644
--- a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
@@ -2,8 +2,11 @@
namespace Drupal\content_moderation\Entity\Handler;
+use Drupal\content_moderation\ModerationInformationInterface;
use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Customizations for node entities.
@@ -11,6 +14,32 @@ use Drupal\Core\Form\FormStateInterface;
class NodeModerationHandler extends ModerationHandler {
/**
+ * The moderation information service.
+ *
+ * @var \Drupal\content_moderation\ModerationInformationInterface
+ */
+ protected $moderationInfo;
+
+ /**
+ * NodeModerationHandler constructor.
+ *
+ * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info
+ * The moderation information service.
+ */
+ public function __construct(ModerationInformationInterface $moderation_info) {
+ $this->moderationInfo = $moderation_info;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
+ return new static(
+ $container->get('content_moderation.moderation_information')
+ );
+ }
+
+ /**
* {@inheritdoc}
*/
public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
@@ -38,7 +67,7 @@ class NodeModerationHandler extends ModerationHandler {
/* @var \Drupal\node\Entity\NodeType $entity */
$entity = $form_state->getFormObject()->getEntity();
- if ($entity->getThirdPartySetting('content_moderation', 'enabled', FALSE)) {
+ if ($this->moderationInfo->getWorkFlowForEntity($entity)) {
// Force the revision checkbox on.
$form['workflow']['options']['#default_value']['revision'] = 'revision';
$form['workflow']['options']['revision']['#disabled'] = TRUE;
diff --git a/core/modules/content_moderation/src/Entity/ModerationState.php b/core/modules/content_moderation/src/Entity/ModerationState.php
deleted file mode 100644
index 379ff60..0000000
--- a/core/modules/content_moderation/src/Entity/ModerationState.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-
-namespace Drupal\content_moderation\Entity;
-
-use Drupal\Core\Config\Entity\ConfigEntityBase;
-use Drupal\content_moderation\ModerationStateInterface;
-
-/**
- * Defines the Moderation state entity.
- *
- * @ConfigEntityType(
- * id = "moderation_state",
- * label = @Translation("Moderation state"),
- * handlers = {
- * "access" = "Drupal\content_moderation\ModerationStateAccessControlHandler",
- * "list_builder" = "Drupal\content_moderation\ModerationStateListBuilder",
- * "form" = {
- * "add" = "Drupal\content_moderation\Form\ModerationStateForm",
- * "edit" = "Drupal\content_moderation\Form\ModerationStateForm",
- * "delete" = "Drupal\content_moderation\Form\ModerationStateDeleteForm"
- * },
- * "route_provider" = {
- * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
- * },
- * },
- * config_prefix = "state",
- * admin_permission = "administer moderation states",
- * entity_keys = {
- * "id" = "id",
- * "label" = "label",
- * "uuid" = "uuid",
- * "weight" = "weight",
- * },
- * links = {
- * "add-form" = "/admin/config/workflow/moderation/states/add",
- * "edit-form" = "/admin/config/workflow/moderation/states/{moderation_state}",
- * "delete-form" = "/admin/config/workflow/moderation/states/{moderation_state}/delete",
- * "collection" = "/admin/config/workflow/moderation/states"
- * },
- * config_export = {
- * "id",
- * "label",
- * "published",
- * "default_revision",
- * "weight",
- * },
- * )
- */
-class ModerationState extends ConfigEntityBase implements ModerationStateInterface {
-
- /**
- * The Moderation state ID.
- *
- * @var string
- */
- protected $id;
-
- /**
- * The Moderation state label.
- *
- * @var string
- */
- protected $label;
-
- /**
- * Whether this state represents a published node.
- *
- * @var bool
- */
- protected $published;
-
- /**
- * Relative weight of this state.
- *
- * @var int
- */
- protected $weight;
-
- /**
- * Whether this state represents a default revision of the node.
- *
- * If this is a published state, then this property is ignored.
- *
- * @var bool
- */
- protected $default_revision;
-
- /**
- * {@inheritdoc}
- */
- public function isPublishedState() {
- return $this->published;
- }
-
- /**
- * {@inheritdoc}
- */
- public function isDefaultRevisionState() {
- return $this->published || $this->default_revision;
- }
-
-}
diff --git a/core/modules/content_moderation/src/Entity/ModerationStateTransition.php b/core/modules/content_moderation/src/Entity/ModerationStateTransition.php
deleted file mode 100644
index 95a115b..0000000
--- a/core/modules/content_moderation/src/Entity/ModerationStateTransition.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-
-namespace Drupal\content_moderation\Entity;
-
-use Drupal\Core\Config\Entity\ConfigEntityBase;
-use Drupal\content_moderation\ModerationStateTransitionInterface;
-
-/**
- * Defines the Moderation state transition entity.
- *
- * @ConfigEntityType(
- * id = "moderation_state_transition",
- * label = @Translation("Moderation state transition"),
- * handlers = {
- * "list_builder" = "Drupal\content_moderation\ModerationStateTransitionListBuilder",
- * "form" = {
- * "add" = "Drupal\content_moderation\Form\ModerationStateTransitionForm",
- * "edit" = "Drupal\content_moderation\Form\ModerationStateTransitionForm",
- * "delete" = "Drupal\content_moderation\Form\ModerationStateTransitionDeleteForm"
- * },
- * "route_provider" = {
- * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
- * },
- * },
- * config_prefix = "state_transition",
- * admin_permission = "administer moderation state transitions",
- * entity_keys = {
- * "id" = "id",
- * "label" = "label",
- * "uuid" = "uuid",
- * "weight" = "weight"
- * },
- * links = {
- * "add-form" = "/admin/config/workflow/moderation/transitions/add",
- * "edit-form" = "/admin/config/workflow/moderation/transitions/{moderation_state_transition}",
- * "delete-form" = "/admin/config/workflow/moderation/transitions/{moderation_state_transition}/delete",
- * "collection" = "/admin/config/workflow/moderation/transitions"
- * }
- * )
- */
-class ModerationStateTransition extends ConfigEntityBase implements ModerationStateTransitionInterface {
-
- /**
- * The Moderation state transition ID.
- *
- * @var string
- */
- protected $id;
-
- /**
- * The Moderation state transition label.
- *
- * @var string
- */
- protected $label;
-
- /**
- * ID of from state.
- *
- * @var string
- */
- protected $stateFrom;
-
- /**
- * ID of to state.
- *
- * @var string
- */
- protected $stateTo;
-
- /**
- * Relative weight of this transition.
- *
- * @var int
- */
- protected $weight;
-
- /**
- * {@inheritdoc}
- */
- public function calculateDependencies() {
- parent::calculateDependencies();
-
- if ($this->stateFrom) {
- $this->addDependency('config', ModerationState::load($this->stateFrom)->getConfigDependencyName());
- }
- if ($this->stateTo) {
- $this->addDependency('config', ModerationState::load($this->stateTo)->getConfigDependencyName());
- }
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getFromState() {
- return $this->stateFrom;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getToState() {
- return $this->stateTo;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getWeight() {
- return $this->weight;
- }
-
-}