Problem/Motivation
An InvalidArgumentException occurs when accessing an entity's revisions list if no revision exists in the currently active language.
The exception is thrown from Drupal/Core/Entity/Controller/VersionHistoryController::loadRevisions, which is called from Drupal/Core/Entity/Controller/VersionHistoryController::revisionOverview.
This doesn't affect nodes, as nodes use \Drupal\node\Controller\NodeController::revisionOverview to display the list of revisions.
Steps to reproduce
I oringinally experienced this issue with a custom entity, but this seems to also happen on all entities that use the VersionHistoryController such as the core \Drupal\block_content\Entity\BlockContent entity.
Here are steps to reproduce with the BlockContent entity:
- Install using standard profile in English
- Enable Content Translation module
- Add the French language
- Create a BlockContent type under /admin/structure/block-content
- Enable ‘Show language selector on create and edit pages’ and ‘Enable translation’ options in the block type's ‘Language Settings’
- Create and place an instance of such a block under /admin/structure/block
- Switch the site's language (I am using the language switcher for this)
- Visit the block's revisions page under /admin/content/block/1/revisions
- Notice that the exception is thrown
Proposed resolution
Change the Drupal/Core/Entity/Controller/VersionHistoryController::loadRevisions function to check if a language exists for each revision with hasTranslation before loading it with getTranslation.
Remaining tasks
Fix Drupal/Core/Entity/Controller/VersionHistoryController::loadRevisions
Add test coverage
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3589757-versionhistorycontroller---invalidargumentexception.patch | 828 bytes | semiaddict |
Issue fork drupal-3589757
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 #3
semiaddict commentedI submitted an MR for this.
Attached is a patch.
Comment #4
cilefen commented