Problem/Motivation
I found this bug with the help of an LLM, due to a report from users seeing the error "Non-translatable fields can only be changed when updating the original language." when attempting to save a translation of a node. There are several other issues related to this error, in Entity Reference Revisions and in Paragraphs, but this one can be narrowed down to the color field module.
I must admit I am not entirely familiar with the issue, and it took quite a bit of debugging to narrow it down. As far as I understand, the issue is that we have some data normalisation in \Drupal\color_field\Plugin\Field\FieldType\ColorFieldType::preSave, but that is not always triggered, and can lead to failed validation.
Steps to reproduce
Best to review the test coverage in the MR
See test-only job fail at https://git.drupalcode.org/issue/color_field-3607068/-/pipelines/869668/...
Proposed resolution
Add \Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldWidgetBase::massageFormValues potentially means we can drop the ::preSave logic, but I'm not sure.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork color_field-3607068
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 #3
mstrelan commentedComment #4
mstrelan commentedcspell--
Comment #5
akshay kashyap commentedI tested this locally and was able to reproduce the issue before applying the MR.
Testing steps:
color_field, content_translation, language, andnodemodules.#HEXHEXstorage format.(#E70000).Before applying the patch, saving the translation failed with:
After applying the MR and clearing caches, I repeated the same steps. The translation saved successfully, no validation error was shown, and the original color value remained unchanged.
I also reviewed the implementation, and moving the normalization to
ColorFieldWidgetBase::massageFormValues()makes sense since it ensures the submitted value matches the configured storage format before entity validation runs. The added functional test provides good regression coverage for both uppercase and lowercase storage formats.RTBC ++.
Comment #6
akshay kashyap commented