function ContentModerationState::loadFromModeratedEntity
Same name in other branches
- 9 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
- 8.9.x core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
- 10 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
Loads a content moderation state entity.
@internal This method should only be called by code directly handling the ContentModerationState entity objects.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: A moderated entity object.
Return value
\Drupal\content_moderation\Entity\ContentModerationStateInterface|null The related content moderation state or NULL if none could be found.
12 calls to ContentModerationState::loadFromModeratedEntity()
- ContentModerationResaveTest::testContentModerationResave in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationResaveTest.php - Tests that Content Moderation works with entities being resaved.
- ContentModerationStateTest::doTestContentModerationStateDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state entity.
- ContentModerationStateTest::doTestContentModerationStatePendingRevisionDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state pending entity revisions.
- ContentModerationStateTest::doTestContentModerationStateRevisionDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state entity revisions.
- ContentModerationStateTest::doTestContentModerationStateTranslationDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state translations.
File
-
core/
modules/ content_moderation/ src/ Entity/ ContentModerationState.php, line 129
Class
- ContentModerationState
- Defines the Content moderation state entity.
Namespace
Drupal\content_moderation\EntityCode
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');
// New entities may not have a loaded revision ID at this point, but the
// creation of a content moderation state entity may have already been
// triggered elsewhere. In this case we have to match on the revision ID
// (instead of the loaded revision ID).
$revision_id = $entity->getLoadedRevisionId() ?: $entity->getRevisionId();
$ids = $storage->getQuery()
->accessCheck(FALSE)
->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', $revision_id)
->allRevisions()
->execute();
if ($ids) {
/** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
$content_moderation_state = $storage->loadRevision(key($ids));
}
}
return $content_moderation_state;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.