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

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

mstrelan created an issue. See original summary.

mstrelan’s picture

Issue summary: View changes
mstrelan’s picture

Issue summary: View changes
Status: Active » Needs review

cspell--

akshay kashyap’s picture

I tested this locally and was able to reproduce the issue before applying the MR.

Testing steps:

  • Enabled the color_field, content_translation, language, and node modules.
  • Added French as a second language.
  • Enabled content translation for the Article content type and enabled Hide non-translatable fields on translation forms.
  • Added a non-translatable Color Field using the default #HEXHEX storage format.
  • Configured the field to use the HTML5 Color Widget.
  • Created an English article with an uppercase color value (#E70000).
  • Added a French translation and changed only the title.

Before applying the patch, saving the translation failed with:

"Non-translatable fields can only be changed when updating the original language."

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 ++.

akshay kashyap’s picture

Status: Needs review » Reviewed & tested by the community