Problem/Motivation

VersionHistoryController::loadRevisions() calls $revision->getTranslation($currentLangcode) on every revision when the entity type is translatable. This was added in #3356684 so the revision overview links use the current language.

The call assumes each revision has a translation in the current content language, and that isn't always true. For example, a revision may predate the entity or field becoming translatable, so it exists only in another language. Then getTranslation() throws an InvalidArgumentException ("Invalid translation language ... specified"). The revision history page fails instead of listing the revisions.

Steps to reproduce

  1. Install Drupal 11 with the standard profile.
  2. Enable the language and content_translation modules.
  3. Add a second language, for example Spanish (es). URL prefix negotiation is on by default, so /es/... sets the content language to es.
  4. Make a media type translatable at /admin/config/regional/content-language.
  5. Create an English media item of that type. Optionally save it again with "Create new revision" so there are several revisions. Do not add a Spanish translation.
  6. Visit /media/{id}/revisions. It works.
  7. Visit /es/media/{id}/revisions. You get a WSOD with InvalidArgumentException: Invalid translation language (es) specified.

Proposed resolution

Only call getTranslation() when the revision is a TranslatableInterface and hasTranslation($currentLangcode) is true. Otherwise, yield the revision unchanged. Add a kernel test covering a revision with no translation in the current language.

Issue fork drupal-3625812

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

v1nk created an issue. See original summary.

v1nk’s picture

Issue summary: View changes

v1nk’s picture

Assigned: v1nk » Unassigned
Status: Active » Needs review
smustgrave’s picture

Version: 11.x-dev » main
Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs steps to reproduce, +Needs tests

Thank you for opening.

The IS appears to be missing some sections that should be added back, especially steps to reproduce section tagging for both.
Also bugs will need test coverage of some kind.

Issues need to land in main first and could be backported.

v1nk’s picture

Assigned: Unassigned » v1nk
Issue summary: View changes

v1nk changed the visibility of the branch 3625812-versionhistorycontrollerloadrevisions-throws-when to hidden.

v1nk’s picture

Assigned: v1nk » Unassigned
Status: Needs work » Needs review

Thanks @smustgrave

The PR is reopened to the main branch now.
I added steps to reproduce and test coverage.