diff --git a/field_collection.module b/field_collection.module index 66a4179..2b27e5c 100644 --- a/field_collection.module +++ b/field_collection.module @@ -1501,6 +1501,7 @@ function field_collection_remove_submit($form, &$form_state) { $parents = $parent_element['#field_parents']; $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $_field_state = drupal_array_get_nested_value($form_state['field']['#parents'], $address); // Go ahead and renumber everything from our delta to the last // item down one. This will overwrite the item being removed. @@ -1522,9 +1523,11 @@ function field_collection_remove_submit($form, &$form_state) { // Move the entity in our saved state. if (isset($field_state['entity'][$i + 1])) { $field_state['entity'][$i] = $field_state['entity'][$i + 1]; + $_field_state[$i] = $_field_state[$i + 1]; } else { unset($field_state['entity'][$i]); + unset($_field_state[$i]); } } @@ -1559,8 +1562,16 @@ function field_collection_remove_submit($form, &$form_state) { $input[$key]['_weight'] = $weight++; } } + + foreach ($field_state['entity'] as $i => $info) { + if (!$info->item_id) { + unset($field_state['entity'][$i]); + unset($_field_state['entity'][$i]); + } + } drupal_array_set_nested_value($form_state['input'], $address, $input); + drupal_array_set_nested_value($form_state['field']['#parents'], $address, $_field_state); field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state); $form_state['rebuild'] = TRUE;