Problem/Motivation
After I change source language of a node (basically, any translatable and revisionable entity), revision history is lost.
Steps to reproduce:
- Install "Content translation" module
- Add language other than English (i.e. French)
- In "Basic page" content type settings, enable the following:
-- Create new revision by default
-- Enable translation
-- Show language selector on create and edit pages
- Create new basic page in English
- Change title/body, write something in "Revision log message", save
- Go to edit of the same page, change language to "French", write something in "Revision log message", save
- Go to "Revisions" tab
Expected result: see all node revisions
Actual result: only the last revision is shown
Why this happens:
In NodeController::revisionOverview():
<?php
foreach ($this->getRevisionIds($node, $node_storage) as $vid) {
/** @var \Drupal\node\NodeInterface $revision */
$revision = $node_storage->loadRevision($vid);
// Only show revisions that are affected by the language that is being
// displayed.
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
?>
The second check ($revision->getTranslation($langcode)->isRevisionTranslationAffected()) fails, because change of the source language
does not set revision_translation_affected flag. So - all revisions except the last one are skipped in the loop.
Proposed resolution
Always set revision_translation_affected flag when changing default node language.
Remaining tasks
- Write the patch
- Add test
User interface changes
No UI change
API changes
No API change
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2961670-testonly.patch | 1.32 KB | valthebald |
Comments
Comment #2
valthebaldAttached is the test-only patch (expected to fail)
Comment #4
miro_dietikerDidn't test this in detail, but the revision tabs are filtered: They only show the revisions that affected the current user interface language.
Did you check the revision tab with switching the languages?
IMHO the tab should by default list all revisions with an optional exposed filter to limit the languages. The current behavior is highly confusing and frustrating users.
Comment #11
kunalkursija commentedTried "steps to reproduce" and confirming the behavior mentioned in the issue is true.
In Drupal 7, It seems like language change in node was not tracked in revisions. This resulted in all revisions of the node irrespective of the language being visible on the revisions listing page. Whereas Drupal 8 onwards, The node's language change is tracked and revisions that belong to the translation are only visible.
Looks like for Drupal 8 onwards this is an intentional behavior as language code is what differentiates one translation from another, Whereas in Drupal 7 it used to be nid's that varied from translation to translation.
I am not sure what the actual behavior should be.