Motivation
This issue is forked from the comments in #1239946: Embedded field collection items with a default value result in new items on save and #1662998: Create configuration option to ignore chosen collected fields when checking for an empty field collection. There have been many requests for the following functionality:
- Using the embedded widget, field collection shows only created collections with an "add another item" button.
- When no created collections exist, field collection shows an "add an item" button, and nothing else.
Proposed Solution
This was prototyped in #1239946-39: Embedded field collection items with a default value result in new items on save, but needs to be reworked as its own option for the new dev branch.
Comments
Comment #0.0
RobW CreditAttribution: RobW commentedAdded reference to the meta
Comment #1
coredumperror CreditAttribution: coredumperror commentedI really need this functionality for my site, and I'd be more than happy to simply patch my local copy of field_collection to fix this issue, but I have no idea which section of code from the various patches on that page contains the removed prototype of this functionality. Could someone please point me in the right direction, so that I can patch field_collection to quiet the complaints from my users?
Comment #2
servantleader CreditAttribution: servantleader commentedAre this and related issues going to be addressed, or has development on this module been abandoned? Without fixing this, the module is only usefull for simple use cases (it is almost useless if you want a radio select without a N/A option). I would start writting the code myslef if I knew that it would be reviewed and commited, if not, I need to find a diferent solution than this module.
Comment #3
hhebert CreditAttribution: hhebert commentedIs there any development about this issue ?
Comment #4
coredumperror CreditAttribution: coredumperror commentedI'm fairly sure that the underlying problem here was fixed in the December release (7.x-1.0-beta5), but I'm not positive. I remember being very happy to see that something related to this had changed for the better, but I can't recall what, exactly.
Comment #5
hhebert CreditAttribution: hhebert commentedWith the last version of Field_collection and Entity, I still have the problem of an empty field_collection show in my form when i have required fields instead of a "Add another" button only.
Comment #6
DaneMacaulay CreditAttribution: DaneMacaulay commentedattached adds setting to remove initial field collection form
Comment #7
tkbcreative CreditAttribution: tkbcreative commented@DaneMacaulay - thank you very much - your patch in #6 solved this issue for me
Comment #8
steven.wichers CreditAttribution: steven.wichers commentedFor single value collections the patch in #6 does not appear to do anything other than remove the field collection forms entirely.
Comment #8.0
steven.wichers CreditAttribution: steven.wichers commentedheaders
Comment #10
valentin schmid CreditAttribution: valentin schmid commentedPatch #6 solves the issue perfectelly. Patched against 7.x-1.0-beta7.
Thank you!
Comment #12
czigor CreditAttribution: czigor commentedMaybe changing the default value to FALSE will make pass the tests. Also existing sites relying upon showing the first blank item won't break.
Comment #13
mlncn CreditAttribution: mlncn commentedFantastic work! This is a lifesaver. Going into production now (patched 7.x-1.x-dev and yes running that), hope it will be committed soon.
Comment #14
Adam Wood CreditAttribution: Adam Wood commentedThere are issues with using this patch with the Field Collection Node Clone module. When you clone a node with field collections using this patch, it will remove the first item in every field collection.
I haven't had a chance to look into it further yet, however I thought I'd flag it up. We just had to temporarily remove this functionality whilst cloning content.
Comment #15
gagarine CreditAttribution: gagarine commentedPatch #12 works perfectly. Thanks.
Comment #16
jmuzz CreditAttribution: jmuzz commentedUse single quotes when possible for consistency with Drupal code standards and the rest of the module.
It should be singular since there will only be one initial item.
I think it needs a similar condition for hide blank items. The option doesn't make sense if hide blank items isn't checked so it shouldn't appear or work when it's not.
Capitals letters at the start and periods at the end please.
Comment #17
milos.kroulik CreditAttribution: milos.kroulik commentedPatch from #12 doesn't apply to beta8 anymore.
Comment #18
czigor CreditAttribution: czigor commentedIt applies to dev.
Comment #19
milos.kroulik CreditAttribution: milos.kroulik commentedSorry, it seems to me, that latest dev is currently identical with beta 8:
http://cgit.drupalcode.org/field_collection/log/
Comment #20
czigor CreditAttribution: czigor commentedHow are you trying to apply the patch? For me it applies without problem.
Comment #21
liquidcms CreditAttribution: liquidcms commentedfrom original issue description i see:
would this suggest that when i am first creating a node which has a FC field with number of values = 1; i should see ONLY an "Add" button and no initial FC form? Even though the field setting states:
it sounds as though this would only apply for multivalued items. (and sure enough i do not get an Add button for my field but the single FC edit form as i used to get prior to patch)
i am not sure why we wouldn't want an Add button EVERY TIME when we state we want an Add button..
Comment #22
Nick Bell CreditAttribution: Nick Bell as a volunteer commentedApologies for amateurism, don't know how to propose a new patch properly (I have just attached mine) but patch #12 didn't work with 7.x-1.0-beta8+11-dev until I made the following tweak:
I'm not quite clear about the "hide blank item" vs "hide initial item" distinction but ticking both boxes achieves what I want.
Nick
Comment #23
Nick Bell CreditAttribution: Nick Bell as a volunteer commented(accidentally created comment - please delete)
Comment #24
Chris Burge CreditAttribution: Chris Burge commentedjmuzz posted some fixes that need to made when he changed the issue status to 'Needs Work'. The attached patch implements those fixes.
Comment #25
Chris Burge CreditAttribution: Chris Burge commentedRegarding the Field Collection Clone module, we can open an issue to address the issue described by #14 once this patch has been committed.
Comment #26
milos.kroulik CreditAttribution: milos.kroulik commentedPatch in #24 seems to be working fine.
Comment #27
meecect CreditAttribution: meecect as a volunteer commented#24 works, however, it would be nice if we had control of the button text. I use the custom add another module, which allows you to set the text that appears on the default 'add another' and 'remove' button. This module adds a third possibility, but we can't control the text. In my case, it's a form that is adding children, so my buttons normally say 'add another child', and 'remove child'.
When I enable this module, the button initially says 'Add another item', and then if i click it, I see the form for the blank item, but the button changes to 'add another child'.
Comment #28
Chris Burge CreditAttribution: Chris Burge commented@meecect - Have you tried using hook_form_alter?
Comment #29
logaritmisk CreditAttribution: logaritmisk commentedI hade issues that the first item was detected as empty, when it wasn't. This was only when host node was new (not saved yet).
It was an easy fix, I switched
!isset($form[$field_name][$element_langcode][0]['#entity']->item_id)
tofield_collection_item_is_empty($form[$field_name][$element_langcode][0]['#entity'])
Comment #30
milos.kroulik CreditAttribution: milos.kroulik commented#27 seems to seems to be a regression. The patch shouldn't limit other modules.
Comment #31
Chris Burge CreditAttribution: Chris Burge commentedThe issue described by #27 is not a regression. The "Custom Add Another" module is a dependent module. Custom Add Another needs to account for the change made by this patch downstream when it implements hook_preprocess_field_multiple_value_form().
Comment #32
ashzade CreditAttribution: ashzade commentedThank you! Patch #29 with Custom Add Another is a great combination. The only issue I see that the "Order" column is shown until I add the first row.
Comment #33
mvlabat CreditAttribution: mvlabat as a volunteer commentedApplying the previous patch breaks the field collection subfields which bave their (css/js) attachements.
You can test this, for instance, with Geofield and Addressfield Autocomplete combination.
To reproduce it you have to add a field collection containing geofield populated from Addressfield Autocomplete field.
This patch fixes this issue.
Comment #34
Valentine94Looks nice to me. +1 to RTBC.
Comment #35
Max_Headroom CreditAttribution: Max_Headroom commentedDoes the job. +1 RTBC
Comment #36
Max_Headroom CreditAttribution: Max_Headroom commentedComment #38
jmuzz CreditAttribution: jmuzz commentedThanks all. It's committed and will appear in the next dev version.
I also took the chance to change the wording on the help text for these options to try to make it more clear what the difference is.