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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcoscano’s picture

Same 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

marcoscano’s picture

Status: Active » Needs review
bojanz’s picture

Status: Needs review » Needs work

Looks like you uploaded the wrong patch.

marcoscano’s picture

Status: Needs work » Needs review
FileSize
3.07 KB

sorry!
attached the correct one

leslieg’s picture

I 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.

leslieg’s picture

Status: Needs review » Reviewed & tested by the community
mjgruta’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.9 KB

The patch works but needs a little tweak because the patch should be applied inside the module and not in other location.

kriboogh’s picture

I 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.

Chris Matthews’s picture

The 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.

Checking patch inline_entity_form.module...
error: while searching for:
 *   The form state of the parent form.
 */
function inline_entity_form_entity_form_submit($entity_form, &$form_state) {
  $ief_id = $entity_form['#ief_id'];
  $instance = $form_state['inline_entity_form'][$ief_id]['instance'];
  // Instantiate the controller and validate the form.
  $controller = inline_entity_form_get_controller($instance);
  $controller->entityFormSubmit($entity_form, $form_state);
  inline_entity_form_cleanup_entity_form_state($entity_form, $form_state);

  if ($entity_form['#op'] == 'add') {
    // Determine the correct weight of the new element.
    $weight = 0;
    if (!empty($form_state['inline_entity_form'][$ief_id]['entities'])) {
      $weight = max(array_keys($form_state['inline_entity_form'][$ief_id]['entities'])) + 1;
    }
    // Add the entity to form state, mark it for saving, and close the form.
    $form_state['inline_entity_form'][$ief_id]['entities'][] = array(
      'entity' => $entity_form['#entity'],
      'weight' => $weight,
      'form' => NULL,
      'needs_save' => TRUE,
    );
  }
  else {
    $delta = $entity_form['#ief_row_delta'];
    $form_state['inline_entity_form'][$ief_id]['entities'][$delta]['entity'] = $entity_form['#entity'];
    $form_state['inline_entity_form'][$ief_id]['entities'][$delta]['needs_save'] = TRUE;
  }
}


error: patch failed: inline_entity_form.module:967
error: inline_entity_form.module: patch does not apply