public ModerationInformation::getDefaultRevisionId($entity_type_id, $entity_id)
Returns the revision ID of the default revision for the specified entity.
Parameters
string $entity_type_id: The entity type ID.
int $entity_id: The entity ID.
Return value
int The revision ID of the default revision, or NULL if the entity was not found.
Overrides ModerationInformationInterface::getDefaultRevisionId
File
- core/modules/content_moderation/src/ModerationInformation.php, line 94
 
Class
- ModerationInformation
 - General service for moderation-related questions about Entity API.
 
Namespace
Drupal\content_moderation
Code
public function getDefaultRevisionId($entity_type_id, $entity_id) {
  if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
    $revision_ids = $storage->getQuery()
      ->condition($this->entityTypeManager->getDefinition($entity_type_id)->getKey('id'), $entity_id)
      ->sort($this->entityTypeManager->getDefinition($entity_type_id)->getKey('revision'), 'DESC')
      ->range(0, 1)
      ->execute();
    if ($revision_ids) {
      return array_keys($revision_ids) [0];
    }
  }
}
Please login to continue.