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
- Install Drupal 11 with the standard profile.
- Enable the language and content_translation modules.
- Add a second language, for example Spanish (es). URL prefix negotiation is on by default, so /es/... sets the content language to es.
- Make a media type translatable at
/admin/config/regional/content-language. - 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.
- Visit /media/{id}/revisions. It works.
- 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
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
Comment #2
v1nk commentedComment #4
v1nk commentedComment #5
smustgrave commentedThank 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.
Comment #6
v1nk commentedComment #9
v1nk commentedThanks @smustgrave
The PR is reopened to the
mainbranch now.I added steps to reproduce and test coverage.