Problem / Motivation

When the node form has any kind of AJAX callback that gets triggered before form submission, multiple field values after index 0 are removed when creating a new translation.

Steps to Reproduce

I have EN as my default language. My EN node has an unlimited Text field and has several values populated. When I Add translation and save, multiple field values (after index 0) are removed from the new translation. This occurs with all unlimited fields that are ET enabled.

  1. Enable Entity Translation, Workbench Moderation and Workbench Email
  2. Enable a new language in Regional and Language settings
  3. Add unlimited, translated Text field to basic Page
  4. Edit Page content type, and in Publishing Options check "Create new revision" and "Enable moderation of revisions". Ensure "Default moderation state" is set to Draft.
  5. Create new EN Basic page, filling out ~5 values in the unlimited Text field and Save node form.
  6. Go to Translate tab and add Translation for an enabled language
  7. In Publishing Options, change Draft to Published (observe the AJAX callback occur)
  8. Save the node form and observe missing Text field values.
  9. You can also observe problems by clicking Add Another after triggering the AJAX callback. You will notice all text fields will vanish except for the first.

Workbench Email was the module that surfaced the issue only because it adds an #ajax callback to the node form. To be clear, Workbench Moderation/Email is not at fault here. Any #ajax on the node form will cause this error to occur.

Environment

I first discovered this on a pretty large site, so I've repoduced on vanilla 7.26 codebase.

Modules installed (Non-core):

Entity Translation 7.x-1.0-beta3
Workbench Moderation 7.x-1.3
Workbench Email 7.x-2.2
Token 7.x-1.5

Solutions

I've roughly tracked the issue down to entity_translation.module's function entity_translation_field_attach_form() and function entity_translation_prepare_element(). I am unsure exactly where the problem is but after debugging form data in these functions, I can see that the form value elements for the translated language only contain value 0. I can see that function entity_translation_prepare_element() adds additional values back to the element but they are not reflected after saving the form.

Comments

Nick Robillard’s picture

Issue summary: View changes
Nick Robillard’s picture

Title: Node form AJAX causes multiple field values after index 0 to not be copied to new translation » Node form AJAX causes multiple field values after index 0 to be removed when creating new translation
Issue summary: View changes
james.williams’s picture

I would suggest trying the patch from #2339315: Source language prepopulated values should be also included in $form_state['field'] as I believe this issue and the problem in that ticket are caused by the same underlying thing - that the field state data structure in $form_state is not replicated for new translations despite the field values being copied from the source language.

mpp’s picture

See my comment on https://www.drupal.org/node/2339315#comment-9548843 the patch only partially solves the issue.
I agree that the problem must be somewhere in the form state since POST data for the fields with missing values are identical for both scenario's (translation & save, translation with ajax manipulation then save).

mpp’s picture

Priority: Normal » Major

Changed priority to major since the problem is wider than multiple text fields, it happens on all AJAX manipulations on the node edit and the issue is a quite common use case and causes loss of data.