Drupal core and setup
- I found this issue in Drupal 9.2.19
- I have no chance to test weather this bug is in Drupal 9.3
- Related Modules: Content Moderation, Language, Content Translation, Configuration Translation, Interface Translation.
- At least Four languages are added.
Problem/Motivation
- Logged in as None-admin user, such 'content editor'.
- English node and subsequent translations were created and moved through the CM (Content Moderation) process , draft, review, send back, review, publish, archive and un-archive. So the Source node (EN) and any created translation is now in Draft state after being unarchived, After creating more translations or when trying to re-Publish the English node (Draft) the error "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved." is displayed and the node cannot be saved.
- English node was published and a translated node was published. Another translations is created as draft or needs review. Subsequent translations can not be created as draft or published.
Steps to reproduce
- As Content Editor, Add a Content type fill in required fields
- Save and Publish
- Create and Publish 2 translations
- Edit the English node and Save and Archive the page, leaving the translations published
- Edit the English node, Save and un-archive the page
- Edit one translation, Save and Archive it
- Edit the EN node and try to publish
Actual results
- error "The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved."
Proposed resolution
I made a patch file to change the Class EntityChangedConstraintValidator:
diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php
index 5a7b4b90c6..14e8f8b4a5 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php
@@ -31,8 +31,12 @@ public function validate($entity, Constraint $constraint) {
// been edited and saved in the meanwhile. Therefore, compare the
// changed timestamps of each entity translation individually.
if ($saved_entity->getTranslation($langcode)->getChangedTime() > $entity->getTranslation($langcode)->getChangedTime()) {
- $this->context->addViolation($constraint->message);
- break;
+ $a = $saved_entity->getLoadedRevisionId();
+ $b = $entity->getLoadedRevisionId();
+ if ($a == $b) {
+ $this->context->addViolation($constraint->message);
+ break;
+ }
}
}
}
Related Articles
- Drupal 8 Node Lock Issue, https://www.drupal.org/project/drupal/issues/2744851
- Core interfaces can go over max_input_vars, https://www.drupal.org/project/drupal/issues/1565704
| Comment | File | Size | Author |
|---|---|---|---|
| core9.2-node-lock-translations-2744851.patch | 1.16 KB | gung wang |
Issue fork drupal-3285657
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
gung wang commentedComment #3
gung wang commentedComment #4
gung wang commentedComment #5
gung wang commentedComment #6
gung wang commentedComment #7
cilefen commentedComment #9
rzanetti commentedIn my case when I was trying to create a German translation of the node, based on the English version, I was receiving the error "The content has either been modified by another user, or you have already submitted modifications". By debugging the EntityChangedConstraintValidator.php->validade function, I was able to identify the error was with the French revision version,
So, in order to solve this, I just open the French version, save a new revision of it, and then everything works fine
Comment #10
omar alahmedI got similar to Rzanetti's scenario, I got the error when I was working on a draft (not the latest revision), and after I revert to the last revision, the error has gone, it seems there is something with the revisioning.
Comment #11
mabho commentedI came across the issue described in this thread because I was experiencing the same issue as @Gung Wang.
I would say we can describe the problem in simpler terms:
Now, to the heart of the problem: when a translation is published after the latest revision, author/user cannot save a new revision in the original language any longer.
Comment #12
rory downes commentedHi,
In my case we had a published English translation (the main language) and a few others. We also had a not published Italian translation.
When clicking add to German (no translation yet), editing the content and clicking on save this translation we got this message.
This patch worked Drupal core 9.5.8. I tested as admin and as a content editor.
Regards Rory
Comment #13
mstiI had the same problem, D 9.5.10
The suggested fix worked.
Comment #14
macsim commentedSame problem for me on a D9.5.11.
The provided patch fixed it.
Thanks
Comment #16
edmund.dunn commentedWe used this successfully. We had this same error on 10.2.2. Two revisions, one created by an automated migration job, the other by an editor, both within a few hours. This created a conflict of some sort. This solved the issue. Well done!
Comment #19
bserem commentedI made an MR against 11.x
It's nothing new, it's the same patch from 4 years ago, superb work from @gungwang!
@cilefen you added no comments as to why this needs work, so I'm bumping it to needs review.
The patch works and does solve the issue. In our case it was also a migration that created revisions. Languages are enabled but the problem exists even without translations in place.
Comment #21
joshuamiIn my testing of the patch, it worked for most use cases but failed on some edge cases related to creating a new translated revision in a new moderation state (for example, moving content from published to archived and back to draft). It would hide the error, but the validation still prevented the revision from being saved.
This updated approach checks to see whether a new revision will be created by the moderation state change in addition to just comparing revision IDs. Helpful when translation is being turned on for moderated content that was not previously translatable or in cases where published status was not a translated field.
I've also added some test coverage.
Comment #23
smustgrave commentedLeft some comments around the test.