How to reproduce:

  • Enable content translation on a content type
  • Add an field with multiple values
  • Create content and then try to save / update a translation
  • Results in PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'add_more' for column 'delta' at row

Normally the occurrence of add_more is removed by field_default_extract_form_values (modules/field/field.default.inc).
I've traced the way how this is done in a normal form and it seems we miss a validation call in translation_edit_form_save_submit.
Thus I've added field_attach_form_validate before calling field_attach_update.

Frankly speaking I've no clue if this is the proper way to do this but it seems to work quite well ;)

Comments

sun’s picture

Yay, that sounds like a test plan :) Do you know how to write tests?

sun’s picture

Title: Issue with multivalue fields » field_default_extract_form_values() is not invoked

Better title.

das-peter’s picture

Hehe, I shouldn't write reproduction instructions - forces me writing tests... ;)
Updated patch includes tests. Hope they meet the requirements - I've just modified the tests provided by translation_node.

das-peter’s picture

Damn, don't know how the tabs sneaked in...

plach’s picture

Project: Content translation » Entity Translation
Version: 7.x-2.x-dev » 7.x-1.x-dev
fietserwin’s picture

Title: field_default_extract_form_values() is not invoked » entity_translation passes empty fields to the storage layer
Priority: Normal » Major
Status: Needs review » Needs work
StatusFileSize
new407 bytes

Patch converted to entity_translation. Test part gave me errors, so I had to skip that one.

Patch seems to solve the problem for numeric fields for me, but now I get this error on an empty taxonomy field:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tid' cannot be null: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 8 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1300313880 ) in taxonomy_field_update() (regel 1702 van modules\taxonomy\taxonomy.module).

fietserwin’s picture

Title: Add basic tests for the translation creation/editing workflow » entity_translation passes empty fields to the storage layer
Assigned: das-peter » Unassigned
Category: task » bug
Status: Needs review » Needs work

Replacing the patched line with;

Old (as in patch):

  ...
  $handler->setTranslation($translation, $form_state['values']);
  field_attach_form_validate($form['#entity_type'], (object) $form['#entity'], $form, $form_state);
  field_attach_update($form['#entity_type'], $form['#entity']);
  ...

new:

  ...
  $handler->setTranslation($translation, $form_state['values']);
  field_attach_form_validate($form['#entity_type'], (object) $form['#entity'], $form, $form_state);
  entity_form_submit_build_entity($form['#entity_type'], (object) $form['#entity'], $form, $form_state);
  field_attach_update($form['#entity_type'], $form['#entity']);
  ...

or with:

  ...
  $handler->setTranslation($translation, $form_state['values']);
  field_attach_form_validate($form['#entity_type'], (object) $form['#entity'], $form, $form_state);
  field_attach_submit($form['#entity_type'], $form['#entity'], $form, $form_state);
  field_attach_update($form['#entity_type'], $form['#entity']);
  ...

Seems to actually save the translation. Anyway, the removal of empty fields is done by the submit handler, not the validate handler. So perhaps the validate line should not be in here at all.

However, I get too many other errors and notices, page not found errors, etc. to reliably patch this single error. I'm also not too deep into fields yet as to say whether my suggestion is the way to go or not. So I won't make a patch out of this.

Aside: for a normal node save, for the empty field removal, you get a trace like;

...
node_form_submit() (submit handler for the form)
  node_form_submit_build_node()
    entity_form_submit_build_entity()
      field_attach_submit()
        _field_invoke_default($op = 'extract_form_values')
        _field_invoke_default($op = 'submit')
          _field Invoke()
            field_default_submit()
              // Filter out empty values.
              $items = _field_filter_items($field, $items);
              // Reorder items to account for drag-n-drop reordering.
              $items = _field_sort_items($field, $items);
plach’s picture

Status: Needs work » Closed (duplicate)

#1098106: Translated fields aren't validated (or processed with presave and submit field_attach_ hooks) has a RTBC patch that should fix this issue. Please move there and confirm.

plach’s picture

Title: entity_translation passes empty fields to the storage layer » Add basic tests for the translation creation/editing workflow
Category: bug » task
Status: Closed (duplicate) » Needs work
StatusFileSize
new7.14 KB

Sorry, reopening this since we have some yummy tests here :)

Here is a rerolled version, tests don't pass atm: peter would you have a look to this?

das-peter’s picture

Assigned: Unassigned » das-peter
das-peter’s picture

StatusFileSize
new18.99 KB

Tests in the patch work like a charm. I've extended it with tests for url alias / pathauto stuff.
The tests in the attached patch are also included it the last patch here #1155134: Integrate pathauto bulk generation

plach’s picture

Status: Needs work » Needs review
plach’s picture

Title: entity_translation passes empty fields to the storage layer » Add basic tests for the translation creation/editing workflow
Assigned: Unassigned » das-peter
Category: bug » task
Status: Needs work » Fixed
StatusFileSize
new9.05 KB

Committed the attached patch to HEAD, thanks!

I left out the path tests because they were failing and the pathauto ones because they'll need to go in within the other patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 2965d9e on master, et-permissions-1829630, factory, et-fc, revisions by plach:
    Issue #944874 by das-peter, plach: Added basic tests for the translation...

  • Commit 2965d9e on master, et-permissions-1829630, factory, et-fc, revisions, workbench by plach:
    Issue #944874 by das-peter, plach: Added basic tests for the translation...