Problem/Motivation
It is impossible to add a new translation in case the user wants to keep the same settings for comments across all translations of the node.
Steps to reproduce
- Install standard
- Install content translation
- Add language (in my case Polish)
- Go to content translation settings and make Article translatable. Only check Title and Body field, unselect the rest, especially the Comments field. Also select "Hide non translatable fields on translation forms"
- Create a node in default language (English)
- Go to the Translate tab and add Polish translation.
- Fill the form and submit.
- "Non-translatable fields can only be changed when updating the original language."

Proposed resolution
CommentFieldItemList needs to implement it's own hasAffectingChanges that only check if status property has changed. If not it will check all properties, included the computed once like:
statuscidlast_comment_timestamplast_comment_namelast_comment_uidcomment_count
And these properties will all be set to 0 until the new entity revision has been saved.
hasAffectingChanges in FieldItemList simply check !$this->equals($original_items);
https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/lib/Drupal/C...
However in the hasAffectingChanges doc it is written:
/**
* Determines whether the field has relevant changes.
*
* This is for example used to determine if a revision of an entity has
* changes in a given translation. Unlike
* \Drupal\Core\Field\FieldItemListInterface::equals(), this can report
* that for example an untranslatable field, despite being changed and
* therefore technically affecting all translations, is only internal metadata
* or only affects a single translation.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3015675
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
matsbla commentedTo reproduce it I also had to select "Hide non translatable fields on translation forms" so I added that to the steps to reproduce.
Still I'm not really sure what you try to achieve. What do you mean with "keep the same settings for comments across all translations of the node"? What settings are you talking about?
Do you want to make the comments non-translatable? In that case, maybe instead make the comment type you use non-translatable.
Comment #3
zaporylieThanks for updating issue summary @matsbla.
Please note that "Comments" property, that can be found in /admin/config/regional/content-language under Content refers to "Comment Settings" section in the Node edit form (Open/Closed/Hidden) not to Comment entity.
Comment #5
matsbla commentedI think
CommentFieldItemListneeds to implement it's ownhasAffectingChangesthat only check if status property has changed. If not it will check all properties, included the computed once like:statuscidlast_comment_timestamplast_comment_namelast_comment_uidcomment_countAnd these properties will all be set to 0 until the new entity revision has been saved.
hasAffectingChangesin FieldItemList simply check!$this->equals($original_items);https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/lib/Drupal/C...
However in the
hasAffectingChangesdoc it is written:https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/lib/Drupal/Core/Field/FieldItemListInterface.php#L280-288
Comment #6
matsbla commentedComment #7
matsbla commentedComment #9
matsbla commentedAdding test.
Comment #11
matsbla commentedComment #12
matsbla commentedComment #13
jungle@matsbla, thanks for working on this!
Reproduced following the "Steps to reproduce" in IS with Simplified Chinese. And confirmed the patch fixed it.
Should start with "Tests", "Tests making changes on entity with hidden non-translatable comment field."
Micro-optimization:
$this->assertSession()called twice, each time it returns a new instance. So save it as a local variable would be better.Otherwise, it's RTBC to me.
Comment #14
jungleChange the target version to 9.1.x. Addressing #13
Comment #15
jungleA comma should follow the last multiline array item. Found: 'article'
Fixing one CS violation. Missing ','
Comment #16
sam152 commentedUpdating the issue summary with the resolution that @matsbla wrote up in #5.
Comment #17
sam152 commentedReviewed for the bug smash initiative :). I'm not a translation expert, but based on your analysis and the docblock for
hasAffectingChanges, this looks like an unambiguous slam dunk.Setting back to NW, but will keep an eye on the issue to RTBC.
Maybe strict equals here? Especially when dealing with all the weirdness that comes with zeros.
I love this test to cover the bug, but since this is also a public method/API, it might be nice to have a more specific test (maybe in
CommentFieldItemList) that calls the method directly, with a few basic test cases? Broad functional tests are super valuable for coverage, but I always appreciate a few integration tests to narrow down the exact problematic code-paths when tracking down test fails.Missing full stop?
I wonder if we should assert the positive case here, aka "The page was saved successfully!", since if for whatever reason this message changed, that change wouldn't ever fail this test and thus it may never get updated.
Alternatively (or additionally), it might be helpful to submit the form WITH a "status" change and assert the validation message does come up.
Comment #18
ravi.shankar commentedHere I have fixed point no. 1 and 3 of comment #17.
It still needs work for the remaining points of comment #17.
Comment #19
matsbla commentedThanks for the reviews and help!
Here is fix for point 4 in comment #17. However, the test already view the translation and assert that is returns code 200, which should confirm that the translation has been successfully saved.
I don't think it is possible, as the comment field settings are untranslatable and the form is configured with "Hide non translatable fields on translation forms", the field is hidden and can't be changed on the translation form.
Comment #22
berdirI think it would be better to assert an actual change, you could change the title in the translation and make sure that shows up.
that this is an access denied on HEAD if there is no translation is imho a bug and I have an issue that changes it so it does the fallback, so that would then no longer assert much.
Comment #23
berdirAlternatively, we can also remove it now that we assert the success message, which I guess is also sufficient.
Comment #25
lendudeTook out the deprecated methods in the test and removed the 200 assert per #23 (which I agree with)
Comment #26
lendudeQuick manual test on the site where we ran into this seems to show that this only helps for published nodes. If the original is unpublished, the translation still gives the error.
Didn't dig into this and didn't try to reproduce on a clean install yet, so might be something on this particular project.
Comment #29
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #31
herved commentedI just encountered this on a project.
I tested on the main branch and it is still valid/relevant so I will create a MR from patch #25.
I was not able to reproduce #26 so I suspect it is project-specific.
Comment #33
herved commentedI addressed the remaining point 2 from #17, a unit test involved a lot of mocking so I went with a kernel one.
For phpstan, not sure if (or how) we should actually address this, it simply uses the magic methods...
Comment #34
herved commentedI believe #3025039: New non translatable field on translatable content throws error would also cover this here.
I guess if that one goes in, we should ask ourselves what CommentFieldItemList::hasAffectingChanges really does and if we really want to change it.
OTOH I would not count on that issue to go in... the current solution there is probably not good enough at the moment.
Comment #35
smustgrave commentedLeft some comments on the MR.
Comment #37
idebr commentedAdded the following changes to the merge request:
mainCommentTranslationUITestis now set through the API instead of through the user interface$userinCommentTranslationUITestto avoid needing a$uservariableCommentItemTest::testCommentHasAffectingChanges,but the scope of test is very narrow so a comment quickly becomes redundant.Patch attached without the changes to test code for composer patches.
Comment #38
smustgrave commentedThink since this is introducing a new function to a used server probably need a CR.
Not sure if this counts as an API change (think not) but the section in the summary appears to be missing saying if it is or not.