Problem/Motivation

Content moderation is now making use of forward revisions but ContentEntityBase::hasTranslationChanges has not been updated to cover this case and it will return false results from the comparison now as it will compare a forward with a default revision and the method is used at couple of places during entity save.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-2833049

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

hchonov created an issue. See original summary.

tstoeckler’s picture

We discussed this at the Entity Field API triage meeting with core and Entity API maintainers and agreed on the current classification as "major".

Not sure about the solution yet, but this seems closely related to #2833084: $entity->original doesn't adequately address intentions when saving a revision

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.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.4.x-dev » 8.5.x-dev

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

plach’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new928 bytes

Here's a fix for this, test coverage is still missing.

plach’s picture

StatusFileSize
new959 bytes

Performance optimization

The last submitted patch, 5: entity-revision_translation_changes-2833049-5.patch, failed testing. View results

dani3lr0se’s picture

I'm interested in helping out with this issue. Would someone be able to provide some steps to test this? What specifically should I be looking for when reviewing this? I also realize that the issue is tagged as needs tests, but am I reviewing the tests or the actual content with revisions, etc.? Thanks for your work and also for your time and help. I greatly appreciate it. :)

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.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.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.

johnchque’s picture

Adding some tests for this. Somehow the untranslatable field is not displayed on translation even with the hidden option disabled.

johnchque’s picture

My bad, that field should not be displayed anyway. Tests are passing locally, let's see if that's the case in testbot.

The last submitted patch, 11: entity-revision_translation_changes-2833049-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Ok, this is tricky.

\Drupal\Core\Entity\ContentEntityStorageBase::createRevision() actually specifically uses the untranslatable field values from the default revision, that's why this isn't failing, the translation still has the values of the default revision and only the translatable fields initially match the latest draft of EN. That's pretty confusing, you don't see them on edit, but you see those old values on the translation form then. Of course the expectation could also vary based on whether or not the user saves it as a draft or as published.

So it's actually specifically a paragraphs problem because we are currently using the latest revision in our entity_reference_revisions_entity_revision_create() hook and that matches user expectations IMHO. The user expectations that we have seen so far is that users create a draft in default-lang and one in a translation, then they expect to see the paragraphs from that draft and even further, if they make further changes to the default-lang draft, they expect to see the new paragraphs in the translation draft as well.

Of course it gets weird once you publish the translation *before* the default language, then that would basically already publish the untranslatable fields. But the current behavior is just as weird in the other direction (that you have a mix of latest-revision and default-revision values). I am uploading a new test patch that better shows the current behavior, but that's not relevant anymore for this issue.

Long story short, this issue is with the current behavior of createRevision() *not* relevant for validation (when only using core), but I'm considering to open an issue to change that behavior and then it will become relevant.

hchonov’s picture

Long story short, this issue is with the current behavior of createRevision() *not* relevant for validation (when only using core), but I'm considering to open an issue to change that behavior and then it will become relevant.

But one can create a forward revision also without using "createRevision" and then we have a relevant problem in hasTranslationChanges :).

maximpodorov’s picture

BTW, if ContentEntityBase::hasTranslationChanges() is called several times (e.g. for different languages) and (see its code) $this->original is not set, $original is loaded from the DB every time. I suggest to cache $original in the entity. This can be related to #2961399: Support parallel translation forward revisions on untranslatable fields

berdir’s picture

hchonov’s picture

The referenced issue still has the same problem as mentioned by @maximpodorov, as even with the cache of the method's outcome the original unchanged entity will be loaded for each translation being checked. This problem is significant only if hasTranslationChanges is called outside the saving process, as there we set $this->original early in the saving process. However we have two constraint validators, which have the mentioned problem - \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator::validate() and \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraintValidator::validate(). I've opened an issue for this - #3007031: hasTranslationChanges on multiple languages outside of saving process is costly.

berdir’s picture

I created #3007233: Draft translations should be based on the latest revision of the source language, not the published version for my proposal above.

@hchonov: Yes, you could create a new revision without createRevision() but I think that isn't really supported/supposed to work :)

plach’s picture

@hchonov: Yes, you could create a new revision without createRevision() but I think that isn't really supported/supposed to work :)

Yep, besides making me cry ;) doing that would also skip hook_entity_revision_create() and friends, which is similar to manually instantiating an entity instead of using the storage's ::create() method: you can do it but it may cause troubles.

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.

maximpodorov’s picture

Re-roll of the patch from #12.

Status: Needs review » Needs work

The last submitted patch, 22: entity-revision_translation_changes-2833049-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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.

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.

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.

namisha jadhav’s picture

Re-roll of the patch 22

berdir’s picture

Issue tags: -Needs tests

#2839195: Add a method to access the original property at least partially addresses this, I'm not certain if the current implementation there is up to date, we can still keep this issue to add the test coverage and verify that it does.

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.

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

danielveza’s picture

Converted the patch to an MR, and fixed the test from the patch while I was at it. Letting the pipeline run.