Steps to reproduce:

* A clean install
* Download and install the field_collection module (dev version) (it requires entity, drush downloads automatically)
* Edit the basic page content type
* Add an embedded field collection (default settings, unlimited values)
* Add the already existing field_image field to this field collection (default settings)
* Add a new basic page
* Upload a test image
* Click the 'Remove' button to remove the field-collection item row
* See that the image is still there :(

I've traced it down a bit and somehow the field keeps a filled default_value with an existing fid. Setting this default_value to NULL (in the function field_collection_field_widget_form) removes the image, but I couldn't figure out when or where to properly fix this. (Always setting the default_value to NULL is not a fix :))

sidenote: I also found a probably related issue, where I would add/remove various item rows with and without uploading images and all of a sudden, new rows were pre-filled with one of the uploaded images. If the above issue is fixed, I assume this will be quite impossible to happen.

Files: 
CommentFileSizeAuthor
#3 removing-field-collection-item-row-2075791-2.patch1.69 KBjanaameier
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch removing-field-collection-item-row-2075791-2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#2 removing-field-collection-item-row-2075791-1.patch876 bytesjanaameier
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch removing-field-collection-item-row-2075791-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#1 field_collection.diff876 bytesjanaameier
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch field_collection.diff. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

janaameier’s picture

StatusFileSize
new876 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch field_collection.diff. Unable to apply patch. See the log in the details link for more information.
[ View ]

As the original issue mentions, the problem is that default value is being kept for image fields. This patch works by looping through all the fields of type image and unsetting their default value in hook_field_widget_form.

janaameier’s picture

Status:Active» Needs review
StatusFileSize
new876 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch removing-field-collection-item-row-2075791-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Sorry, I did not read the submitting patches guide properly.

The patch works by checking if the field data is actually set on the field_collection_item, and if not, removing #default_value from element.

The patch has been tested by following the procedure described in the issue, and it is now possible to remove an image row. Furthermore, old rows do not reappear when adding more rows.

janaameier’s picture

StatusFileSize
new1.69 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch removing-field-collection-item-row-2075791-2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Created a new patch with tortoisegit, hopefully that one works

Status:Needs review» Needs work

The last submitted patch, removing-field-collection-item-row-2075791-2.patch, failed testing.

fuo’s picture

The problem seems to be that FieldCollection is not correctly calling the hook_field_delete hook_field_delete_revision or hook_field_delete_update of its subfields. This means that any field which has "extra business" to do before deletion, like a Media Field, will not do its business correctly when a FieldCollection row is removed.

When, for example, a whole Node is deleted, hook_field_delete is called, and this make a Media Field down-count the usage of its image file. FieldCollection also needs to ensure that this happens correctly when a FieldCollection row is removed.

jmuzz’s picture

Priority:Major» Normal
Issue summary:View changes