EntityRepository::getActive does not return a translations most recent revision

Created on 12 September 2019, about 5 years ago
Updated 4 February 2023, almost 2 years ago

Problem/Motivation

When using content moderation and translations, EntityRepository::getActive does not return the most recent translated revision.

To set this up, create a node with 2 pending draft translation revisions. I've been using lightning with paragraphs_demo to quickly set this up.

$nid = 1;
$latest_revisions = [];
$storage = \Drupal::service('entity_type.manager')->getStorage('node');
$entity = $storage->load($nid);
$language_manager = \Drupal::service('language_manager');
$context_definition= new ContextDefinition('language');
/* @var \Drupal\Core\Entity\EntityRepository $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
if ($entity instanceof TranslatableInterface) {
  foreach ($entity->getTranslationLanguages() as $language) {
    $new_context =  new Context($context_definition, $language_manager->getLanguage($language->getId()));
    $contexts = [
      '@language.current_language_context:' . LanguageInterface::TYPE_CONTENT => $new_context,
      '@language.current_language_context:' . LanguageInterface::TYPE_INTERFACE => $new_context
    ];
    $latest_revisions[$language->getId()] = $entity_repository->getActive($entity->getEntityTypeId(), $entity->id(), $contexts);
  }
}

With the above,
$latest_revisions['en']->label(); returns the expected title of the pending English translation revision.
$latest_revisions['de']->label(); returns the unexpected title of the current English translation revision.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

πŸ› Bug report
Status

Needs work

Version

9.5

Component
EntityΒ  β†’

Last updated about 14 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States jasonawant New Orleans, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    The test patch in #5 will need to be updated for D10 coding standards and deprecations.

    If still experiencing it hopefully we get some traction

Production build 0.71.5 2024