protected function ModerationStateFieldItemList::loadContentModerationStateRevision in Config Entity Revisions 8.2
Load the content moderation state revision associated with an entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity the content moderation state entity will be loaded from.
Return value
\Drupal\content_moderation\Entity\ContentModerationStateInterface|null The content_moderation_state revision or FALSE if none exists.
1 call to ModerationStateFieldItemList::loadContentModerationStateRevision()
- ModerationStateFieldItemList::getModerationStateId in src/
ModerationStateFieldItemList.php - Gets the moderation state ID linked to a content entity revision.
File
- src/
ModerationStateFieldItemList.php, line 95
Class
- ModerationStateFieldItemList
- A computed field that provides a content entity's moderation state.
Namespace
Drupal\content_moderation\Plugin\FieldCode
protected function loadContentModerationStateRevision(ContentEntityInterface $entity) {
$moderation_info = \Drupal::service('content_moderation.moderation_information');
$content_moderation_storage = \Drupal::entityTypeManager()
->getStorage('content_moderation_state');
$revisions = $content_moderation_storage
->getQuery()
->condition('content_entity_type_id', $entity
->getEntityTypeId())
->condition('content_entity_id', $entity
->id())
->condition('content_entity_revision_id', $entity
->isNewRevision() ? $entity
->getLoadedRevisionId() : $entity
->getRevisionId())
->condition('workflow', $moderation_info
->getWorkflowForEntity($entity)
->id())
->allRevisions()
->sort('revision_id', 'DESC')
->execute();
if (empty($revisions)) {
return NULL;
}
/** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
$content_moderation_state = $content_moderation_storage
->loadRevision(key($revisions));
if ($entity
->getEntityType()
->hasKey('langcode')) {
$langcode = $entity
->language()
->getId();
if (!$content_moderation_state
->hasTranslation($langcode)) {
$content_moderation_state
->addTranslation($langcode, $content_moderation_state
->toArray());
}
if ($content_moderation_state
->language()
->getId() !== $langcode) {
$content_moderation_state = $content_moderation_state
->getTranslation($langcode);
}
}
return $content_moderation_state;
}