Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My scenario:
I have 2 entity reference using Inline Entity Forms under People -> Accounts.
I use conditional fields on a select field to show only one of the entity reference.
When I submit the form, I get these errors...
Warning: array_diff_key(): Argument #1 is not an array in EntityInlineEntityFormController->entityFormSubmit() (line 307 of sites/all/modules/inline_entity_form/includes/entity.inline_entity_form.inc).
Warning: Invalid argument supplied for foreach() in EntityInlineEntityFormController->entityFormSubmit() (line 308 of sites/all/modules/inline_entity_form/includes/entity.inline_entity_form.inc)
$entity_values = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
I think drupal_array_get_nested_value cannot find the #parents field name from $form_state['values'] because conditional field might have removed it from $form_state.
Is it safe to just add a condition to skip the process when $entity_values is empty?
Comment | File | Size | Author |
---|
Comments
Comment #1
marcoscanoSame here, in my case the form submission was also creating an empty child entity.
Don't know if it's too hackish, but just checking if drupal_array_get_nested_value() returns something before calling the $controller->entityFormSubmit() did the trick for me. Apparently everything OK now.
Patch attached
Comment #2
marcoscanoComment #3
bojanz CreditAttribution: bojanz commentedLooks like you uploaded the wrong patch.
Comment #4
marcoscanosorry!
attached the correct one
Comment #5
leslieg CreditAttribution: leslieg commentedI had a very similar scenario.
My scenario:
I have multiple entity references using Inline Entity Forms under People -> Accounts.
I use conditional fields to display only the entity references selected by the user
When I submit the form, I get the same error listed above:
Warning: array_diff_key(): Argument #1 is not an array in EntityInlineEntityFormController->entityFormSubmit() (line 307 of sites/all/modules/inline_entity_form/includes/entity.inline_entity_form.inc).
Warning: Invalid argument supplied for foreach() in EntityInlineEntityFormController->entityFormSubmit() (line 308 of sites/all/modules/inline_entity_form/includes/entity.inline_entity_form.inc)
Applying the patch successfully remove the errors on my site.
Comment #6
leslieg CreditAttribution: leslieg commentedComment #7
mjgruta CreditAttribution: mjgruta commentedThe patch works but needs a little tweak because the patch should be applied inside the module and not in other location.
Comment #8
kriboogh CreditAttribution: kriboogh commentedI have a similar problem as #1. I have a entity reference field that is hidden using conditional fields when a particular value is selected in a dropdown list. The reference field is a single value field and not required. When I save the host node without filling in any of the child node fields, an empty child node is saved.
I applied the patch from #7 to the latest version "7.x-1.6" but I still get these empty childs being saved.
Comment #9
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 4 year old patch in #7 to inline_entity_form.module does not apply to the latest inline_entity_form 7.x-1.x-dev and if still applicable needs a reroll.