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

  1. enable content translation (depends on language which will get enabled with it) /admin/modules
  2. enable workflows /admin/modules
  3. enable content moderation /admin/modules
  4. add a language (for example: spanish) /admin/config/regional/language
  5. 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
  6. 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

  1. 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
  2. edit and keep in draft
    • notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
    • notice /node/1/revisions has two table rows
  3. 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

  1. 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
  2. edit and keep in draft
    • notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
    • notice /node/1/revisions has two table rows
  3. publish
    • notice /node/1 has tabs: View, Edit, Delete, Revisions, Translate
    • notice /node/1/revisions has three table rows
  4. 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)
  5. 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

  1. edit first node, publish
  2. 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).

Issue fork drupal-3092558

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

YesCT created an issue. See original summary.

yesct’s picture

Issue summary: View changes

formatting steps to reproduce.

yesct’s picture

Issue summary: View changes

fix up html in summary

vijaycs85’s picture

Component: entity system » workflows.module
StatusFileSize
new1.08 MB

I 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.

vijaycs85’s picture

StatusFileSize
new1.09 MB

I just tried with workflows (+ content moderation) as well and couldn't reproduce the issue. Hopefully not missing anything.

yesct’s picture

Issue summary: View changes
StatusFileSize
new846.31 KB

[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 ]

vijaycs85’s picture

Status: Active » Needs review
Issue tags: -Needs tests +Workflow Initiative
StatusFileSize
new2.15 KB

Thanks, @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.

diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityO
perations.php
index 52d2ca3909..e2058c03d3 100644
--- a/core/modules/content_moderation/src/EntityOperations.php
+++ b/core/modules/content_moderation/src/EntityOperations.php
@@ -113,9 +113,10 @@ public function entityPresave(EntityInterface $entity) {
       $current_state = $workflow->getTypePlugin()
         ->getState($entity->moderation_state->value);

-      // This entity is default if it is new, the default revision, or the
-      // default revision is not published.
+      // This entity is default if it is new, the new translation,
+      //  the default revision, or the default revision is not published.
       $update_default_revision = $entity->isNew()
+        || (!$entity->isNew() && isset($entity->original))
         || $current_state->isDefaultRevisionState()
         || !$this->moderationInfo->isDefaultRevisionPublished($entity);
vijaycs85’s picture

Component: workflows.module » content_moderation.module

Status: Needs review » Needs work

The last submitted patch, 8: 3092558-8-test-only.patch, failed testing. View results

yesct’s picture

Issue summary: View changes

[tweak to update issue summary.]

matsbla’s picture

If 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

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aloneblood’s picture

Reproduce 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

k9606’s picture

StatusFileSize
new2.34 KB

When 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)

recrit’s picture

@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.

recrit’s picture

StatusFileSize
new1.59 KB
new2.21 KB

The 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:

       $update_default_revision = $entity->isNew()
         || $current_state->isDefaultRevisionState()
-        || !$this->moderationInfo->isDefaultRevisionPublished($entity);
-
+        || !$this->moderationInfo->isDefaultRevisionPublished($entity)
+        || (
#### COMMENT: If we got here in the logic, then  !$entity->isNew() will always be true.
+          !$entity->isNew()
#### COMMENT: This assumes $entity->original is the default translation. An easier check would be to check !$entity->isDefaultTranslation().
+          // It means entity has been translated.
+          && isset($entity->original)
+          // it means you're saving translation entity.
+          && $entity->original->language()->getId() != $entity->language()->getId()
+          // It means no published revision.
#### COMMENT: This assumes the permissions that are set for the site. If we got here in the logic, then the current state is not the default revision state, ie not published or any other state that should be the default revision.
+          // Normally, anonymous users can see the public content.
+          // Currently, Can not find a best way to do it.
+          && !$entity->access('view', User::load(0))
+        );

New patch #21:

       $update_default_revision = $entity->isNew()
         || $current_state->isDefaultRevisionState()
-        || !$this->moderationInfo->isDefaultRevisionPublished($entity);
+        || !$this->moderationInfo->isDefaultRevisionPublished($entity)
+        || ($entity instanceof TranslatableInterface && !$entity->isDefaultTranslation());
recrit’s picture

Some 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_data table since there is no record for the Spanish translation in the table.
- Moderated views based on the node_field_revision table will display all revision information correctly; however, it will not display information from the base table, example "Content Type".

recrit’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 21: 3092558-21.patch, failed testing. View results

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB
new2.96 KB

The 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.

Status: Needs review » Needs work

The last submitted patch, 25: 3092558-25.patch, failed testing. View results

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new6.44 KB
new4.76 KB

Updated the failing tests with the new expectations for a default revision being created for a draft translation.

Status: Needs review » Needs work

The last submitted patch, 27: 3092558-27.patch, failed testing. View results

recrit’s picture

The 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

recrit’s picture

StatusFileSize
new2.13 KB

The 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.

recrit’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

I 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.

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB
new720 bytes

code cleanup, test still pending.

smustgrave’s picture

Status: Needs review » Needs work

Thanks 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.

recrit’s picture

StatusFileSize
new1.97 KB

The root cause for this display issue of the revision overview page is that the NodeController::revisionOverview() depends on the routed node object / $node function argument for the following:
1. To determine if the node has translations.
2. Assumes that the $node argument is the default node revision.

Proposed Resolution:
Update the NodeController::revisionOverview() to be independent of the $node argument.

Reasoning::
1. The root cause of this display issue is in NodeController::revisionOverview().
2. The entity.node.version_history route is the only "version_history" route so checking for the route and altering it in Drupal\content_moderation\Routing\ContentModerationRouteSubscriber no longer made sense. Previous patches #31 and #34 altered the entity.node.version_history route.
3. By updating NodeController::revisionOverview() only and not updating entity.node.version_history in node.routing.yml with "load_latest_revision", this supports any custom class that exends the NodeController. The custom class would not need to know the semantics that the $node argument 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_data table since there is no record for the translation in that database table.
3. A moderated views view based on the node_field_revision table will display all translation revisions information correctly; however, it will not display information from the base node_field_data table for a draft only translation. Example "Content Type" cannot be displayed. The base data is joined with node_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.

recrit’s picture

Pending:
- 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

recrit’s picture

StatusFileSize
new7.56 KB
new5.59 KB

Patches 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.

recrit’s picture

Status: Needs work » Needs review
smustgrave’s picture

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: -Needs subsystem maintainer review

Asked 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.

recrit’s picture

Issue summary: View changes

updated the issue summary with the approach in "3092558-38--with-tests.patch"

recrit’s picture

Status: Needs work » Needs review
smustgrave’s picture

Issue summary appears to have been updated.

Haven't tested but does this bug affect other entities using revisions?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.25 KB

The 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.

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new7.56 KB

Re-roll of #38 against 11.x and removed the forbidden word "please".

recrit’s picture

@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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new7.56 KB

re-rolled for the latest 11.x changes

recrit’s picture

StatusFileSize
new7.56 KB

Adding a D10.1.x patch.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new92 bytes

The 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.

recrit’s picture

Status: Needs work » Needs review

Created 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

recrit’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

recrit’s picture

no clue what the review bot wants here. Both MR's are passing.

recrit’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

recrit’s picture

Status: Needs work » Needs review

rebased the 11.x MR 5439 since 1 hour after the branch was created it is no longer mergeable...

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Rebased earlier for the test-only job and forgot to post

There was 1 error:
1) Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::testTranslationRevisionsHistory
Behat\Mink\Exception\ResponseTextException: The text "Log Message - French - Draft - Edit 1" was not found anywhere in the text of the current page.
/builds/issue/drupal-3092558/vendor/behat/mink/src/WebAssert.php:811
/builds/issue/drupal-3092558/vendor/behat/mink/src/WebAssert.php:262
/builds/issue/drupal-3092558/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php:491
/builds/issue/drupal-3092558/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
ERRORS!

Was difficult to replicate but believe I'm seeing the issue and change doesn't seem unreasonable.

  • catch committed 12ef050d on 10.2.x
    Issue #3092558 by recrit, vijaycs85, smustgrave, aloneblood, k9606,...

  • catch committed 2feaa299 on 11.x
    Issue #3092558 by recrit, vijaycs85, smustgrave, aloneblood, k9606,...
catch’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

This 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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.