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.
Updated: Comment #0
Problem/Motivation
STR:
- Fresh install of Drupal 7 (drush si) with 7.x-1.x field_collection (0fd332e)
- Add a new field collection to "page" node type, with cardinality Unlimited.
- Add two fields to this field collection: a text field and a file field. Configure file field to allow file types you have available.
- Go to /node/add/page, enter some text in the text field, select a file, and upload it with the Ajax Upload button.
- 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
Comment | File | Size | Author |
---|---|---|---|
#5 | field-collection_2209769_fix-file-fields.patch | 6.95 KB | ezheidtmann |
#5 | field-collection_2209769_fix-file-fields.testonly.patch | 5.35 KB | ezheidtmann |
#4 | field-collection_2209769_fix-file-fields.patch | 1.6 KB | ezheidtmann |
Comments
Comment #1
ezheidtmann CreditAttribution: ezheidtmann commentedBehavior 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.
Comment #2
ezheidtmann CreditAttribution: ezheidtmann commentedFC needs to be cardinality unlimited to get the Remove button.
Comment #3
ezheidtmann CreditAttribution: ezheidtmann commentedCloser 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.
Comment #4
ezheidtmann CreditAttribution: ezheidtmann commentedI think it works. I'm working on a test, if Drupal simpletest works with file uploads.
Comment #5
ezheidtmann CreditAttribution: ezheidtmann commentedWhew, that was tough. Tests are passing locally; could use some cleanup, but I want to see if testbot likes it.
Comment #7
kristofferwiklund CreditAttribution: kristofferwiklund commented