If you attach a field_collection field to a node and use the 'hidden' widget (as I do to use the standalone form to manage my field_collection items), all of your existing field_collection items are deleted upon node form submit. I believe this is a result of the unset() happening in hook_form_alter() on line ~76:

<?php
// Remove all items again in case the form submission fails validation.
  if (!empty($form_state['#field_remove_item'])) {
    foreach ($form_state['#field_remove_item'] as $field_name => $field_values) {
      foreach ($field_values as $field_language => $field_deltas) {
        foreach ($field_deltas as $field_delta) {
          if (isset($form[$field_name][$field_language][$field_delta])) {
            unset($form[$field_name][$field_language][$field_delta]);
          }
        }
      }
    }
  }
?>

Comments

FranciscoLuz’s picture

Hi,

The items being unset in this case are only those that had been removed before a failed form validation occurs.

"All" in this sense does not mean effectively all the items in the field but the user selected ones.

Of course, I am not saying that your assertion is not correct, that might be the cause, although I find it unlikely to be the case.

Try to comment out the line 80 (unset statement) and see if that behaviour still applies.

FranciscoLuz’s picture

Ah!

Another thing that I should state is that this module is not suppose to act on field collection fields because field collection has its own remove button.

Check out the code on line 15, it excludes field collection.

I haven't got the time to investigate that in depth right now but you could test it yourself by disabling this module and see if it has any impact on what you are experiencing whatsoever.

charlie-s’s picture

When I disable this module the field_collection items are not touched. When I enable this module again and save the node edit form of a node that contains field_collection items, they are deleted completely from the database.

field collection has its own remove button.

This is not true for hidden field_collection widgets, and I suspect this is where the problem lies.

FranciscoLuz’s picture

I see.

I wont have time to fix it right now but apparently it is only a matter of finding out what value in the $element array says it is a hidden field and then add a exclusion condition in the "if" statement at line 14.

I will look into this as soon as I can.

pcambra’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Could you try the module with the latest changes and let me know if this has still issues?

If so, how to reproduce this behavior.

pcambra’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Marking this as closed, feel free to reopen after checking the question above.