Problem/Motivation
In #2940204: Translatable fields with synchronization enabled should behave as untranslatable fields with respect to pending revisions we realized that it would be handy to be able specify a $properties parameter to compare only a subset of the item properties.
Proposed resolution
Add it
Remaining tasks
- Validate the proposed solution
- Write a patch
- Reviews
User interface changes
None
API changes
Only BC additions
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | interdiff-2941092-19_23.txt | 1.07 KB | gauravvvv |
| #24 | 2941092-23.patch | 2.63 KB | gauravvvv |
| #19 | 2941092-19.patch | 2.63 KB | kapilv |
| #8 | ignore_width_height_on_untranslatable_field_comparision_2941092_8.patch | 2.61 KB | florianmuellerch |
Issue fork drupal-2941092
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
idflood commentedI found this issue because I had an error while trying to translate a page with an image field. The image field has the "alt" and "title" translatable, and the page content type has the option to hide untranslatable fields turned on.
When trying to save the translation I get the following error:
Notice: Undefined index: width in Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator->hasSynchronizedPropertyChanges() (line 154 of core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php).There are in fact two "issues" with the current check:
- The loop check if any of the property changed and return TRUE if any of them has changed. In this case the "alt" changes but it should still be ok as this is translatable.
- The dimension is missing in the `$items` variable but are present in the `$original_items`. In the error I have it mention the `width` property but it the error would be identical for the `height`.
Comment #3
james.williamsI ran into the same problem that idflood ran into. It actually stopped my client being able to make any changes to translations of content.
I end up seeing this error message (which I'm putting here mostly in the hope that others hitting it might find this comment): "Non-translatable field elements can only be changed when updating the original language." This may be in part because I have implemented the tweaks suggested in the change record around 'untranslatable_fields.default_translation_affected'. It's also possible to run into the "Non-translatable field elements can only be changed when updating the current revision." error message for similar reasons.
The site has an image field, which allows the alt & title text to be translated, but not the file itself (i.e. the target_id). The entity_browser's FileBrowserWidget populates the alt & title properties alongside the target_id in its
massageFormValues()method, but not height & width - core's image widget also leaves the height & weight properties out too though, so I don't believe this is unique to entity_browser. TheImageItemfield class populates height & width onpreSave()(which happens after validation, so these two properties could be skipped from the translation/synchronization validation when they are empty.I don't know which of the following solutions ought to be implemented:
1) Force widgets to populate all the necessary columns for fields (e.g. is the widget at fault for not populating those columns? surely not, if ImageItem is expecting to handle empty height & weight properties anyway.)
2) Move ImageItem's population of height & width to something that runs before validation constraints (but they do run rather early, I'm not sure there is anywhere appropriate yet, is there?)
3) Implement this $properties argument to FieldItemList::equals, though I'm not sure if that would help in this case? I didn't quite follow the motivation.
4) Something else??
I feel terribly dirty about this, but since this was a showstopper for my client, I've produced the attached HACKY patch to get around this very specific instance of the problem. As far as I can see, image fields are the only ones in core that use the 'column_groups' thing that is used for field synchronization between translations, so the hack is limited to 'fixing' image fields. I am 100% aware that this patch should not be what ends up in core, but some of us need a pragmatic fix in the meantime!
Even with this fix, I believe there is a limitation that only one translation can be in draft state at a time -- that could really do with being clearer, both to the user and in code or documentation. Is it even a limitation that we can work towards removing?
All the code around the ContentTranslationSynchronizedFieldsConstraintValidator and FieldTranslationSynchronizer, and the concepts of draft & default revisions combined with translations, make my head spin, so I haven't been able to get any closer to a 'better' solution, sorry. I wish I could!
Comment #5
mistrae commented#3 saved my life. Thanks!
Comment #6
woutervu commentedCan confirm, #3 works. Thanks james.williams!
Comment #7
hchonovSomehow it sounds like another problem addressed in #2988309: Ensure that all field types return TRUE on equals() for the same values. Would you please try the patch from the other issue instead?
Comment #8
florianmuellerchI extended @james.williams patch a bit because it needed to be excluded also in FieldItemList comparisons. Thanks a lot for the initial hints!
Comment #9
mrharolda commented@hchonov, the patch in #2988309: Ensure that all field types return TRUE on equals() for the same values does not fix out issue; it seems that FieldItemList::equals is never called from hasSynchronizedPropertyChanges.
Comment #14
alan-ps commented+1 the same issue (Drupal 8.9.13)
This is how I fixed it by own code:
Comment #15
paulvb commented+1 the same issue (Drupal 8.9.13)
Updated from 8.9.11 to 8.9.13
Comment #17
stefaniev commentedI had the same issue as #2 on Drupal 9.1.5.
The patch in #8 fixed my issue. Thanks!
Comment #18
rcodinaPatch on #8 works for me. The message "Non-translatable field elements can only be changed when updating the original language" has disappeared and I'm now able to save the translation node.
Comment #19
kapilv commentedComment #21
hctom@KapilV, what is the purpose of your new patch? I tried to create an interdiff, but it is completely empty, so I guess it is the same patch as in #8? Please always provide some information in the comment about what you did (plus an interdiff, if you update/reroll a patch), so everybody can follow along.
Comment #22
andrewsuth commentedPatch #8 also works for my case (a lot like james.williams outlined in #3)
I was unable to translate alt fields due to the error "Non-translatable field elements can only be changed when updating the original language."
Comment #23
mlzrSubscribe! Same problem + patch #8 is the solution for me.
Thanks!!
Comment #24
gauravvvv commentedRe-rolled patch #19. Attached interdiff for the same.
#8 was re-rolled by KapilV for drupal9.
Comment #25
berdirThis is a problem, but the issue is very confusing. The title has nothing to do with what the patch is doing, I also feel like there are other existing issues that deal with image fields, but haven't found them yet.
The patch is failing as there are grammar issues, it will need test and hardcoding one specific field type in there is most likely not going to be accepted.
Comment #26
berdirSee #3218426: Using partially synchronized image fields causes validation errors and PHP warnings, this seems to be a regression in 8.9.12 and equally old drupal 9 releases.
Comment #27
gngn commented#8 worked for me.
Comment #30
recrit commentedThis appears to be a duplicate of #3218426: Using partially synchronized image fields causes validation errors and PHP warnings
Comment #32
hitchshockNeed to say that patch #24 also fixed PHP8.1 compatibility issue for me. Exactly fixed the warning:
Warning: Undefined array key "width" in Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator->hasSynchronizedPropertyChanges() (line 159 of core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php).So +1 RTBC
Comment #33
catchThere's no committable patch here. Also marking duplicate of #3218426: Using partially synchronized image fields causes validation errors and PHP warnings.
Comment #34
joseph.olstadPHP 8.1 upgrade on Drupal 10 noticed the Undefined index on width as reported in #32
I used the patch from the other issue #3218426: Using partially synchronized image fields causes validation errors and PHP warnings
It resolved the undefined width notice