Phew.

Set up

1. Put a field_collection field (using the embed widget) on the referenced entity type - e.g. taxonomy term.
2. Add an entity_reference/multi-valued IEF widget on the host entity type configured to reference the above- e.g. Node

Steps to reproduce

1. Create/Edit your host entity form (e.g. Node add)
2. Create 1 new term inline populate your field collection values, save it
3. Fill out some other field on the node which will cause the form to fail validation. For example choose a custom url alias which already exists on some other node.
4. Submit the host form, witness validation error message (e.g. url alias already exists)
5. Submit the host form again (without fixing the invalid path)

Expected results

1. Returned to the same form with the same validation error message

Actual results

1. Fatal error: EntityMalformedException: Missing bundle property on entity of type field_collection_item, WSOD.

Note, this bug was introduced by #1991796: Multi-valued IEF breaks if referenced entity form contains a field collection embed widget. But don't revert that change, since the aim is to get field collection working in IEFs!

CommentFileSizeAuthor
#1 inline_entity_form-2016141-01.patch5.46 KBjamsilver

Comments

jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.46 KB

OK, so the problem is ultimately caused by the fact that inline_entity_form submits the inner entity form during the host form's validation phase (in an #element_validate callback), rather than a submit callback. The result is that if there is an unrelated validation error thrown on the form (if that validation error is thrown *after* ief's validate callback is run) then ief will still go on to execute submit handlers even though the form will never actually go through to submission.

This causes a bad mix between EntityInlineEntityFormController::cleanupFieldFormState() and field collection's field_collection_field_widget_embed_validate() the latter of which expects something which the former cleans up on submission!

The attached patch solves the issue by actually moving ief's submit process into a submit callback so that it can definitely know for sure that all validation has in fact passed.

This patch certainly requires some thorough testing. It is also likely that it could be done a little bit more cleanly. I've just tried to swap out a bit of a function and stick it inside a related submit function.

bojanz’s picture

bojanz’s picture

Status: Needs review » Closed (duplicate)