Problem/Motivation
Motivation:
Inconsistent behavior is confusing, and not seeing translation revisions hinders work of editors.
Problem:
Sometimes revisions tab on translated content only shows original source revisions.
This happens when the original source has a published version, before the translation has any published versions.
Proposed resolution
Show translation revisions on translation revisions tab.
Remaining tasks
- Investigation into cause
- Write test(s)
Steps to reproduce
Install Drupal 8.8+ with no contrib modules
Setup
- enable content translation (depends on language which will get enabled with it) /admin/modules
- enable workflows /admin/modules
- enable content moderation /admin/modules
- add a language (for example: spanish) /admin/config/regional/language
- configure content translation /admin/config/regional/content-language under "Custom language settings" check "Content" and then check the checkbox for Basic Page (leave the default fields checked) and save configuration
- configure workflows /admin/config/workflow/workflows/manage/editorial in the "This workflow applies to" section, next to "Content types", click "Select", check Basic Page, save, save
to see expected behavior
- add draft english content /node/add/page
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has one table row
- edit and keep in draft
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has two table rows
- translate node
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has two table row
- notice /es/node/1/revisions has one table row
to see bug
- add draft english content /node/add/page
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has one table row
- edit and keep in draft
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has two table rows
- publish
- notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
- notice /node/1/revisions has three table rows
- translate node: *set state to draft* as saving translation, as creating the translation see https://www.drupal.org/files/issues/2019-11-05/creating-translation-in-d...
- notice on save goes to /es/node/2/latest
- notice /es/node/2/latest has the translation
- notice /es/node/2/latest has tabs: View, Edit, Latest version, Revisions, Translate
- notice /es/node/2/revisions *unexpectedly* shows the english three revisions and no spanish revisions
- notice /node/2/revisions (as expected) shows the english three revisions (and no spanish revisions)
- can edit the translation again, now, there are two revisions of the translation, but no way to see them via the Revisions tab
Bit more investigation
we can go back to the first case, and explore the as expected behavior a bit more, where neither is published, and publish the original language node
- edit first node, publish
- edit translation
- notice the revisions for the translation show on the translation revision tab /es/node/1/revisions
- notice the revisions for the original node show on the revisions tab /node/1/revisions
User interface changes
For the solution in #38: No changes
API changes
For the solution in #38: No changes
Data model changes
For the solution in #38: No changes
Release notes snippet
For the solution in #38: The node revisions page will now show the correct revisions for the translation even when the translation has never been published (ie draft only).
| Comment | File | Size | Author |
|---|---|---|---|
| #59 | 3092558-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #56 | 3092558-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #5 | Screenshot 2019-11-05 at 19.56.40.png | 1.08 MB | vijaycs85 |
| #6 | Screenshot 2019-11-05 at 20.15.51.png | 1.09 MB | vijaycs85 |
| #7 | creating-translation-in-draft.png | 846.31 KB | yesct |
Issue fork drupal-3092558
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
yesct commentedformatting steps to reproduce.
Comment #3
yesct commentedfix up html in summary
Comment #4
yesct commentedComment #5
vijaycs85I followed all the steps in issue summary except enabling workflow(step #6) and I can confirm that there is no bug (please check the attachment). so it looks like a workflow related issue.
Comment #6
vijaycs85I just tried with workflows (+ content moderation) as well and couldn't reproduce the issue. Hopefully not missing anything.
Comment #7
yesct commented[edit: updated issue summary to highlight the detail, of creating the translation in the *draft* state. so, the bug shows when the source is published, and the translation, is going through revisions in draft.]
[edit: also! woohoo!! thanks for looking at this!! :D ]
Comment #8
vijaycs85Thanks, @YesCT, for the call to explain the issue. I managed to reproduce it locally when adding translation with the 'draft' state.
While debugging, I found the problem is on the content translation module
Drupal\content_moderation\EntityOperations::entityPresave(), where it decides to update the revision. It seems the check for a new translation in non-published status was not adding an entry to the node_field_data table, so the node's language falls back to x-default, which is why we see revisions of English.Adding this change fixes the problem, but it breaks the default version of the translation but we have a test to show the issue.
Comment #9
vijaycs85Comment #11
yesct commented[tweak to update issue summary.]
Comment #12
matsbla commentedIf the revision log table is replaced by a view, maybe we should make sure translations can be configured correctly there:
#1863906: [PP-1] Replace content revision table with a view
Comment #17
aloneblood commentedReproduce steps
1. Create an English node and publish
2. Create a Japanese node and set moderation to draft
Can not see the content type value in the /admin/content/moderated page for the Japanese translated node. (see https://www.drupal.org/project/drupal/issues/3095164)
And we can see there is no Japanese record in the node_field_data table and caused this issue.
The patch do:
1. Update $update_default_revision to true after creating a new no-published translation to let drupal create a record in the node_field_data table
2. Update $update_default_revision to true before the translation node has a publish revision.
Comment #19
k9606 commentedWhen I used the two patches at the same time, I merged them because the number of lines conflicted.(this page #17 and https://www.drupal.org/project/drupal/issues/3006897 #17)
Comment #20
recrit commented@k9606 Please do not post "combo" patches in order to keep the issue focused on a single issue.. You should keep "combo" patches as a custom patch for your build.
Comment #21
recrit commentedThe attached patch simplifies the logic to check for this condition. The content_moderation's original checks already covered the majority of the added logic in patch #17. The attached patch #21 only adds a new condition to check when there is a non-default translation being saved as a non-default state with a published default revision. Example: en is published, es is draft.
See my comments for the original patch below:
New patch #21:
Comment #22
recrit commentedSome more reasons on why this is a bad bug:
Examples below are with a source language of English and translation of Spanish.
When in this state of PUBLISHED default translation (example English) with a new DRAFT only translation (example Spanish), the following occur:
- Revision logs are incorrect as stated in this issue's original report. The route `entity.node.version_history` resolves to the default revision for the current language. There is only the source language (English) that has a default revision.
- Any check for
$entity->hasTranslation(es)with the default revision of the source language will return FALSE, and consequently and loading of the translation with$entity->getTranslation(es)- The Spanish DRAFT will not display in an admin content list view that is based on the
node_field_datatable since there is no record for the Spanish translation in the table.- Moderated views based on the
node_field_revisiontable will display all revision information correctly; however, it will not display information from the base table, example "Content Type".Comment #23
recrit commentedComment #25
recrit commentedThe patch #21 and #17 did not support the translation having a published revision and a draft revision. Those patches would always set the draft as the default revision resulting in no published revision.
The patch attached supports translations having a published revision and a draft revision.
Comment #27
recrit commentedUpdated the failing tests with the new expectations for a default revision being created for a draft translation.
Comment #29
recrit commentedComment #30
recrit commentedThe previous patches #27 and earlier have an issue where you could create a fork of the revisions ultimately resulting in data loss when you have the following:
- Source translationL (ie English): Published and a Draft.
- Translation (ie Spanish): Created initially as a Draft when the source has a draft. Then publish the translation before the Source translation's draft is published.
For this reason, I suggest that we focus this ticket on fixing the node revision overview page only.
Related Issues:
- #2860097: Ensure that content translations can be moderated independently
- #2766957: Forward revisions + translation UI can result in forked draft revisions
Comment #31
recrit commentedThe attached patch alters any "entity.{entity type}.version_history" routes to load the latest version. This will show the correct revisions when there is only a draft version of a translation.
Comment #32
recrit commentedComment #33
smustgrave commentedI don't see the proposed solution in the IS, that will need to be added.
Also as a bug will need a test case showing the bug
Thanks.
Comment #34
recrit commentedcode cleanup, test still pending.
Comment #35
smustgrave commentedThanks for updating the patch but not ready for review yet for the points in #33.
If you're trying to see if the tests pass you can still upload a patch and click "Add test / reset" underneath to run the tests without putting into review.
Comment #36
recrit commentedThe root cause for this display issue of the revision overview page is that the
NodeController::revisionOverview()depends on the routed node object /$nodefunction argument for the following:1. To determine if the node has translations.
2. Assumes that the
$nodeargument is the default node revision.Proposed Resolution:
Update the
NodeController::revisionOverview()to be independent of the$nodeargument.Reasoning::
1. The root cause of this display issue is in
NodeController::revisionOverview().2. The
entity.node.version_historyroute is the only "version_history" route so checking for the route and altering it inDrupal\content_moderation\Routing\ContentModerationRouteSubscriberno longer made sense. Previous patches #31 and #34 altered theentity.node.version_historyroute.3. By updating
NodeController::revisionOverview()only and not updatingentity.node.version_historyinnode.routing.ymlwith "load_latest_revision", this supports any custom class that exends theNodeController. The custom class would not need to know the semantics that the$nodeargument must be the latest revision.Other related issues:
This resolution only fixes the display issue of the node revisions when the source node is published and there is a draft only revision of a translation.
In this scenario, there will not be an entry for the translation in the node_field_data table which can cause the other issues belwo:
1. Any check for $entity->hasTranslation(es) with the default revision of the source language will return FALSE, and consequently and loading of the translation with $entity->getTranslation(es)
2. The translation DRAFT will not display in an admin content list view that is based on the
node_field_datatable since there is no record for the translation in that database table.3. A moderated views view based on the
node_field_revisiontable will display all translation revisions information correctly; however, it will not display information from the basenode_field_datatable for a draft only translation. Example "Content Type" cannot be displayed. The base data is joined withnode_field_revision.nid = node_field_data_node_field_revision.nid AND node_field_data_node_field_revision.langcode = node_field_revision.langcode. Since it joins langauge, there will never be a match.Comment #37
recrit commentedPending:
- patch updated with new tests, most likely added to content_moderation module since it sets the default revision flag.
- new-tests-only patch to show core fails without the new patch
Comment #38
recrit commentedPatches attached:
1. 3092558-38--with-tests.patch: Update from #36 with new tests. This should PASS the automated tests.
2. 3092558-38--tests-only.patch: Only the new tests. This should FAIL the automated tests.
Comment #39
recrit commentedComment #40
smustgrave commentedCleaning up tags some.
Comment #41
smustgrave commentedAsked catch in #needs-review-queue-initative channel and this doesn't need submaintainer review actually.
But still think the issue summary could be updated. Seems to reference 8.8 are thinks the same for D10?
Unknown used in a few spots doesn't seem right.
Comment #42
recrit commentedupdated the issue summary with the approach in "3092558-38--with-tests.patch"
Comment #43
recrit commentedComment #44
smustgrave commentedIssue summary appears to have been updated.
Haven't tested but does this bug affect other entities using revisions?
Comment #45
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #46
recrit commentedRe-roll of #38 against 11.x and removed the forbidden word "please".
Comment #47
recrit commented@smustgrave I have not looked into the new generic entity revision controller that can be used by any entity type. I suspect that it could have this same issue with translations since loading the default translation revision is the same for any type.
Comment #48
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #49
recrit commentedre-rolled for the latest 11.x changes
Comment #50
recrit commentedAdding a D10.1.x patch.
Comment #51
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #54
recrit commentedCreated the following MRs:
- 11.x: MR 5439 based on 3092558-48--D11.patch
- 10.1.x: MR 5440 based on 3092558-49--D10.1.patch
Comment #55
recrit commentedComment #56
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #57
recrit commentedno clue what the review bot wants here. Both MR's are passing.
Comment #58
recrit commentedComment #59
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #60
recrit commentedrebased the 11.x MR 5439 since 1 hour after the branch was created it is no longer mergeable...
Comment #61
smustgrave commentedRebased earlier for the test-only job and forgot to post
Was difficult to replicate but believe I'm seeing the issue and change doesn't seem unreasonable.
Comment #64
catchThis is tricky and I'm not even sure I agree with the concept of not showing revisions for other languages on the revisions tab - but that decision wasn't introduced here so we should make it work how it's currently designed.
Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!