Problem/Motivation

In #2949815: Flagging translations as outdated in a pending revision causes multiple translations to be marked as affected we have hidden the "Flag as outdated" functionality for moderated content due to how late this issue was discovered in the 8.5 development cycle, however this feature is not fundamentally incompatible with pending revisions so we should try to bring it back.

Proposed resolution

An attempt was made to save a new revision for every translation, however it was deemed too risky and not tested enough to be committed.

  1. After "Flag other translations as outdated" is checked mark the latest affected revision of each translation as outdated without creating a new revision by utilizing setSyncing
  2. When we display the checkbox, determine its value by looking at the outdated flag of the last affected revision of the current translation.
  3. When unchecking "This translation needs to be updated", update the outdated flag of the last affected revision before we save the entity in a pre save hook, so the metadata of old revisions is correct. Again utilizing setSyncing to avoid the creation of a new revision.

Remaining tasks

  • Propose a valid solution
  • Write a patch
  • Reviews

User interface changes

The "Flag as outdated" checkbox is restored.

API changes

None

Data model changes

None

Issue fork drupal-2950626

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

plach created an issue. See original summary.

plach’s picture

Status: Active » Needs review
StatusFileSize
new9.24 KB
timmillwood’s picture

Status: Needs review » Needs work
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -264,6 +264,41 @@ public function retranslate(EntityInterface $entity, $langcode = NULL) {
+      $metadata = $this->manager->getTranslationMetadata($revision_translation);
+      if (!$metadata->isOutdated()) {
+        /** @var \Drupal\Core\Entity\ContentEntityInterface $new_revision */
+        $new_revision = $storage->createRevision($revision->getTranslation($langcode), $revision->wasDefaultRevision());
+        $metadata = $this->manager->getTranslationMetadata($new_revision);
+        $metadata->setOutdated(TRUE);
+        $storage->save($new_revision);
+      }

I feel this section especially is lacking documentation. Why does a new revision need to be created to mark it as outdated?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

criz’s picture

Just adding that this patch works for us. Having this functionality back would be good to improve the editor experience when working with translations!

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

marcoscano’s picture

StatusFileSize
new9.17 KB

Re-roll for 9.2.x, which also includes some refactoring of the test, to stop using deprecated code.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kosa ilma’s picture

I couldn't apply the patch from #11 on Drupal 9.3.3.
Here is the modified patch.

ravi.shankar’s picture

StatusFileSize
new9.19 KB

Added reroll of patch #11.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sanket1007’s picture

Looks this this is fixed as part of core in latest core version (10.3.1)

kosa ilma’s picture

I can confirm @sanket1007
I have tried on Drupal core 10.3.1 and it is working without the addition of the patch.

charginghawk made their first commit to this issue’s fork.

charginghawk’s picture

Unable to test 10.3 right now, but it seems like the outdated option should still be unavailable since the logic hiding it is still there:

https://git.drupalcode.org/project/drupal/-/blob/11.0.4/core/modules/con...

In any case that code should be removed. Also, we should have steps to reproduce.

Additionally, as a commenter noted, "Why does a new revision need to be created to mark it as outdated?" It doesn't. The condition at the end of markRevisionTranslationsOutdated() should use setSyncing(TRUE) to mark the latest revision translation (what the "Status" column references on node/12345/translations) as outdated:

      $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity_id, $langcode);
      if (!$revision_id) {
        continue;
      }

      /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
      $revision = $storage->loadRevision($revision_id);
      $revision_translation = $revision->getTranslation($langcode);
      $metadata = $this->manager->getTranslationMetadata($revision_translation);
      if (!$metadata->isOutdated()) {
        $metadata->setOutdated(TRUE);
        $revision_translation->setSyncing(TRUE);
        $storage->save($revision_translation);
      }
charginghawk’s picture

Status: Needs work » Needs review
StatusFileSize
new9.03 KB
new2.86 KB

Rerolling #14 for 10.3.x. Also adding the "setSyncing(TRUE)" described above to setOutdated on the current revision instead of creating a new one.

smustgrave’s picture

Status: Needs review » Needs work

Thanks for continuing. Patch should be in an MR though vs patch.

banoodle’s picture

StatusFileSize
new60.05 KB

Pach #14 doesn't apply on 11.1.5.

I re-rolled the patch locally so it applies, but then I get timeout errors when I save nodes with "translations outdated" enabled.

I would submit a MR, but for some reason I don't have sufficient privileges (I'm working to resolve that now).

screenshot of error

banoodle’s picture

StatusFileSize
new9.27 KB

Here is a re-rolled patch that works on D11.1.5.

I realize you prefer an MR. I will try to make one tomorrow once I sort out my permissions/account issues.

I resolved the timeout issues (my bad), and this appears to work well.

banoodle’s picture

Update: even though patch 25 works fine in my local, when I deploy it to Pantheon, I still get "The application did not respond in time." when trying to save a node with the "outdated" option enabled.

yovanny.gomez.oyola’s picture

Patch #22 works well on Drupal 10.3.x. However, I noticed that when a translation is marked using the "Flag other translations as outdated" option, the "This translation needs to be updated" field does not appear when loading the other translations.

To address this, I’ve added a small tweak to Patch #22 to ensure the field is displayed correctly and behaves as expected—just like it does when the content is not moderated.

I’ve attached screenshots showing the behavior after applying the new patch.

mjpa’s picture

I've tried the patch from #27 with the following scenario:

* Node is published in English and French
* Create a new draft in English, tick the "Mark translation as out of date" and save (as draft).

On the translate tab, it shows the French translation as "Published outdated". This seems wrong to me as the published version is not out of date.

Should the published version only be considered out of date once the edit is published?

achap made their first commit to this issue’s fork.

achap’s picture

Status: Needs work » Needs review

I used #27 as a basis to create a MR for the 11.x branch per #23. I also saw the issue where a translation wasn't marked as outdated in certain cases that #27 talks about. To reproduce it you need to:

* Create an en node in published.
* Create a fr node in published.
* Create an it node in draft.
* Edit the en node and check "Flag other translations as outdated".
* Edit the fr node, and you will still see: "Flag other translations as outdated".
* Edit the it node, and you will see "This translation needs to be updated".

Interestingly, the status on the translation overview page is already handling this case correctly. The code from #27 is very similar to the code in ContentTranslationController::overview. I made some small optimizations to the existing patch.

Also I updated the test to make sure the above scenario was captured + a few other ones.

A couple of functional tests are failing but they are unrelated to my change.

smustgrave’s picture

Status: Needs review » Needs work

Will need a green pipeline before moving forward.

MR is almost 1200 commits behind so may need to be rebase

Proposed solution section appears to need to be flushed out.

achap’s picture

Assigned: Unassigned » achap
achap’s picture

Assigned: achap » Unassigned
Issue summary: View changes
Status: Needs work » Needs review

Rebased and tests are now passing. Also updated the proposed resolution to reflect the changes that are being made.

Since my last changes:

  • Added some code to keep the outdated metadata of the last affected revision up to date when saving a translation.
  • Added some code to the test to keep track of this. Noticed a weird bug in the test where the storage was returning wrong results for entities. Seems like using $this->container is deprecated so I switched to using \Drupal and everything worked as expected. See https://www.drupal.org/node/3492500

achap changed the visibility of the branch 2950626-allow-flagging-translations-11.2 to hidden.

achap changed the visibility of the branch 2950626-allow-flagging-translations-11-2 to hidden.

achap changed the visibility of the branch 2950626-allow-flagging-translations-11-2 to hidden.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 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 necessarily 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.

rajiv.singh’s picture

StatusFileSize
new10.94 KB

Re rolled patch Comment#27 for Drupal 11.2.10

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

achap’s picture

Rebased onto the new main branch.

The current PR targets marking a translation as outdated only via the UI but as you can see from the linked issues there is also a need to do this in contrib e.g. TMGMT needs to mark a translation as no longer outdated when an auto translation finishes. There are also MRs open in that module to auto mark content outdated based on information about the node. With the current implementation, the revision metadata would be incorrect if contrib simply called setOutdated.

I think it would be good if core could handle the logic from both markRevisionTranslationsOutdated and updateLastTranslationAffectedRevisionOutdatedStatus in a central place that wasn't tied to the UI. Ideally, just calling the setOutdated method from client code should take care of updating the metadata in revisions via those two methods but client code doesn't need to know about them.

achap changed the visibility of the branch 2950626-allow-flagging-translations-experimental-changes to hidden.

achap’s picture

Issue summary: View changes
Status: Needs work » Needs review
  • Updated the MR to make changes I talked about in #42. Revision history is kept in sync in a pre_save hook so client code doesn't need to do anything but called setOutdated.
  • Moved the markRevisionTranslationsOutdated inside the public interface retranslate method, so that client code can call that method for revisionable entities as well as non revisionable entities.
  • I tried moving everything to the entity builder, but it looks like revisionable entities require being handled in a post save and non revisionable entities need to be handled in the entity builder. So I reverted that and updated the test to catch it breaking if they are moved.
uri_frazier’s picture

The patch 2950626-outdated-40.patch from comment #40 works for me, new changes since then on the MR results in a Cannot apply patch composer error for Drupal 11.3.2

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 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 necessarily 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.

achap changed the visibility of the branch 2950626-allow-flagging-translations-11.3 to hidden.

achap’s picture

Issue summary: View changes
Status: Needs work » Needs review

Updated the merge request to fix latest main conflicts. Created an 11.3 branch for re-roll of latest main.