public static function ContentModerationState::loadFromModeratedEntity in Drupal 9
Same name and namespace in other branches
- 8 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.
11 calls to ContentModerationState::loadFromModeratedEntity()
- ContentModerationStateTest::testChangingContentLangcode in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests changing the language of content without adding a translation.
- ContentModerationStateTest::testContentModerationStateDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state entity.
- ContentModerationStateTest::testContentModerationStatePendingRevisionDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state pending entity revisions.
- ContentModerationStateTest::testContentModerationStateRevisionDataRemoval in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php - Tests removal of content moderation state entity revisions.
- ContentModerationStateTest::testContentModerationStateTranslationDataRemoval 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');
$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', $entity
->getLoadedRevisionId())
->allRevisions()
->execute();
if ($ids) {
/** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
$content_moderation_state = $storage
->loadRevision(key($ids));
}
}
return $content_moderation_state;
}