I'm on D10. The site has a content type, e.g. article, which is translatable and has a standard content moderation workflow (draft, published, archived).

Given a node of that bundle, I need to find the latest default revision for every language of that node.

That default revision may be the last revision of the node or not. For example, a node could have a published EN translation, but also a later draft revision, and a IT published revision but also a relative draft revision.

I've tried

$en_revision = $this->entityTypeManager->getStorage('node')
      ->getLatestTranslationAffectedRevisionId($node->id(), 'en');
$it_revision = $this->entityTypeManager->getStorage('node')
      ->getLatestTranslationAffectedRevisionId($node->id(), 'it');

But those eventually get the latest revision, so the draft one, if existing in that language.

I've also tried

$entity_repository = \Drupal::service('entity.repository');
$en_contexts = $this->getLanguageContexts('en');
$active = $entity_repository->getActive('node', $node_revision->id(), $en_contexts);

  protected function getLanguageContexts($langcode) {
    $prefix = '@language.current_language_context:';
    return [
      $prefix . LanguageInterface::TYPE_INTERFACE => new Context(new ContextDefinition('language'), $langcode),
      $prefix . LanguageInterface::TYPE_CONTENT => new Context(new ContextDefinition('language'), $langcode),

But this doesn't seem to work the translation context, it always return the "latest active" revision, it may be in EN or IT depending on which is the last.

I've found this relevant issue, so maybe this way won't work.

I've also tried

// try to load the default revision in the default language
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid)
// Get the entity repository service.
$entity_repository = \Drupal::service('entity.repository');

// Load the latest revision of the translated node.
$latest_revision = $entity_repository->getTranslationFromContext($node, $language_code);

But even with this way the context doesn't seem to work.


As asked in the comment, I'll try to describe what I mean for default revision.

I consider a "default" revision one is in a moderation state which has the relative checkbox enabled in its configuration.

So, for a standard moderation setup, published and archived would be a default revision state.


As far I can understand (or find e.g. #1 or #2) the default revision is for Drupal the revision which is loaded when it's not specified the revision, or in other words it's the one used in the canonical routes.

As example, for a single language EN site, for a node with the following revision history

vid  moderation_state
7   draft
6   published
5   draft
4   archived
3   published
2   draft
1   draft

I'd consider 3, 4, 6 as default revision and 6 the latest default revision

Being my case a multilanguage site, and being the official terminology and documentation unclear, I actually I am not 100% sure what could be considered a latest default revision by the system in that setup.

Having a EN language default site with a node translated in EN and IT, I know the node vid will increase each time a translation is saved, so from the "vid" itself is not possible to understand if that revision has been "created" for one translation or another.

If I understand correctly, the system relies on the revision_translation_affected property to determine if a translation is affected by a revision - aka, that revision should be considered "meaningful" for that language?

As example the EN translation revisions of a node could be:

vid  moderation_state
10   draft
7   published
5   draft
4   published
2   draft
1   draft

While for the IT could be

vid  moderation_state
9   published
8   draft
6   published
3   draft

Therefore, in the above example the latest EN default revision should be 7, while the IT should be 9.

I suppose this should be the result, despite 9 having also the EN translation in published/default revision state, because the relative revision_translation_affected should be true only for the IT translation.

  • Could you explain what “default revision” is in this context? As an example, for an English node, in an English-default site, what properties of a particular revision would denote it as “default”?
    – Clive
    Feb 22 at 19:18
  • BTW I’m asking that because it’s been known for a long time that there are serious issues with Drupal’s revision system, especially with regard to translations, and also in regard to terminology. See drupal.org/project/drupal/issues/1643354 for a nice little rabbit hole to follow
    – Clive
    Feb 22 at 19:21
  • @Clive I updated the answer, trying to explain what I know about the argument and a couple of examples.
    – Giuseppe
    Feb 23 at 10:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.