summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/Entity
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-10 07:16:25 (GMT)
committerNathaniel Catchpole2017-08-10 07:16:25 (GMT)
commite6f77992cdec3f037af2ffa54dca987344c0650d (patch)
tree51e5308533c070bdf7ab284d409c0b7363d0a347 /core/modules/content_moderation/src/Entity
parentbff6783e980edf0ae4877c8c4c64517ac54af4cd (diff)
Issue #2893888 by plach, Sam152, amateescu, evilehk: Content moderation state entity field data not removed when the host field data is
Diffstat (limited to 'core/modules/content_moderation/src/Entity')
-rw-r--r--core/modules/content_moderation/src/Entity/ContentModerationState.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/modules/content_moderation/src/Entity/ContentModerationState.php b/core/modules/content_moderation/src/Entity/ContentModerationState.php
index 39b0ff4..aedcb5f 100644
--- a/core/modules/content_moderation/src/Entity/ContentModerationState.php
+++ b/core/modules/content_moderation/src/Entity/ContentModerationState.php
@@ -4,6 +4,7 @@ namespace Drupal\content_moderation\Entity;
use Drupal\content_moderation\ContentModerationStateInterface;
use Drupal\Core\Entity\ContentEntityBase;
+use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\TypedData\TranslatableInterface;
@@ -143,6 +144,44 @@ class ContentModerationState extends ContentEntityBase implements ContentModerat
}
/**
+ * Loads a content moderation state entity.
+ *
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * A moderated entity object.
+ *
+ * @return \Drupal\content_moderation\ContentModerationStateInterface|null
+ * The related content moderation state or NULL if none could be found.
+ *
+ * @internal
+ * This method should only be called by code directly handling the
+ * ContentModerationState entity objects.
+ */
+ public static function loadFromModeratedEntity(EntityInterface $entity) {
+ $content_moderation_state = NULL;
+ $moderation_info = \Drupal::service('content_moderation.moderation_information');
+
+ if ($moderation_info->isModeratedEntity($entity)) {
+ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
+ $storage = \Drupal::entityTypeManager()->getStorage('content_moderation_state');
+
+ $ids = $storage->getQuery()
+ ->condition('content_entity_type_id', $entity->getEntityTypeId())
+ ->condition('content_entity_id', $entity->id())
+ ->condition('workflow', $moderation_info->getWorkflowForEntity($entity)->id())
+ ->condition('content_entity_revision_id', $entity->getLoadedRevisionId())
+ ->allRevisions()
+ ->execute();
+
+ if ($ids) {
+ /** @var \Drupal\content_moderation\ContentModerationStateInterface $content_moderation_state */
+ $content_moderation_state = $storage->loadRevision(key($ids));
+ }
+ }
+
+ return $content_moderation_state;
+ }
+
+ /**
* Default value callback for the 'uid' base field definition.
*
* @see \Drupal\content_moderation\Entity\ContentModerationState::baseFieldDefinitions()