entity_translation_prepare_element() currently clones the $form_state array and passes it to field_attach_form(). field_attach_form() will proxy to many other hooks within the system, some of whom alter the form_state for their later use. All of this is attached to the clone entity_translation_prepare_element() creates, but the $form_state is passed by reference to entity_translation_prepare_element() meaning Drupal intends to get whatever changes were made to form_state there back out for the rest of the system.

Inline Entity Form and perhaps other modules (paragraphs?, field_collection?) do EXACTLY this. IEF in particular adds settings to the form_state for later use during its submit. These values are missing as the code currently stands and cause a cascade of errors that ultimately result in a db error. Simply NOT cloning the $form_state and passing it as normal to field_attach_form() seems to solve this. Obviously some testing is probably in order, but I wanted to get more eyeballs on this, so please, take a look.

Eclipse

CommentFileSizeAuthor
#2 2651050-2.patch677 byteseclipsegc

Comments

EclipseGc created an issue. See original summary.

eclipsegc’s picture

Status: Active » Needs review
StatusFileSize
new677 bytes

CODE!

joelpittet’s picture

Nice find, going to give this a try(in production where else;). If only form_state was an object:P Oh wait, d8

heathdutton’s picture

Going to try this as well. Nice!

plach’s picture

It's been a while since I wrote that code, but IIRC the idea was exactly to isolate the original form state to avoid unexpected side effects. However, I don't remember having encountered specific issues, it was kind of a precaution. OTOH I'm seeing the value of using the original form state instead, since nested entity forms are clearly a legit use case for that. My only concern is still that performing this change may introduce some unexpected and hard to track down side effect, however the OP is compelling, so I think we should try this.

plach’s picture

Status: Needs review » Postponed

I will try to tag a new release soon, I've been promising that for quite a while now, once I've done that we can commit this and start experimenting with it.

loopduplicate’s picture

I left a related comment in https://www.drupal.org/node/1344672?page=1#comment-10883654 . Basically, the patch from this issue doesn't help. Instead, I use the patch from https://www.drupal.org/node/2339315#comment-10848466 .