Updated: Comment #0

Problem/Motivation

STR:

  1. Fresh install of Drupal 7 (drush si) with 7.x-1.x field_collection (0fd332e)
  2. Add a new field collection to "page" node type, with cardinality Unlimited.
  3. Add two fields to this field collection: a text field and a file field. Configure file field to allow file types you have available.
  4. Go to /node/add/page, enter some text in the text field, select a file, and upload it with the Ajax Upload button.
  5. Click the Remove button for the field collection (NOT the file field Remove button)

Expected results: empty field collection form will load.
Actual results: Text field is emptied, but uploaded file remains.

The bug was introduced in commit 96eff7c. But reverting that commit is not a viable solution.

Proposed resolution

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ezheidtmann’s picture

Behavior is nearly identical if using an existing node: FC Remove button works to remove the file which was saved, but after uploading a new file, the Remove button behaves as described in original report.

ezheidtmann’s picture

Issue summary: View changes

FC needs to be cardinality unlimited to get the Remove button.

ezheidtmann’s picture

Closer to a solution: this happens because the delta remains the same and the field state for subfields is saved in $form_state['field']['#parents']['field_my_collection']['und'][0]['#fields'], field_collection_remove_submit() doesn't touch that part of $form_state, and file.module file_field_widget_form() uses the field state to store the uploaded fids. Apparently other modules don't use $field_state.

One possible solution is to modify field_collection_remove_submit() to reorder $form_state['field']['#parents']['field_my_collection']['und'] to match the $form_state['values'] shuffling. I will try that tomorrow.

ezheidtmann’s picture

Status: Active » Needs review
FileSize
1.6 KB

I think it works. I'm working on a test, if Drupal simpletest works with file uploads.

ezheidtmann’s picture

Whew, that was tough. Tests are passing locally; could use some cleanup, but I want to see if testbot likes it.

The last submitted patch, 5: field-collection_2209769_fix-file-fields.testonly.patch, failed testing.

kristofferwiklund’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll