This might be a dupe of #1300724: I need a way to let users edit the delta of field-collection items without the use of the edit page (or others, I can't tell)
Currently there are two widgets for Field Collection - either you can edit from the parent's entity form (embedded/subform mode) or hide all together and rely on the inline links to manage field collection items.
If you have a complex field collection bundle then the latter option is probably advisable - having several instances of CKEditor on the page is one reason why you might not want to display the field collection widget on your entity edit forms.
The problem is that if you hide the widget entirely then you can't re-order the field collection items. I get the feeling that it's still up for debate where that re-ordering should occur - either on a separate page or on the entity edit form. Actually I don't really care but it would be nice to have it somewhere!
If I was to implement this, then this is what I would do:
Define a third widget for field collection - "re-order only"
Define a new display mode - not sure what it would be called, something like "title only", or maybe just use teaser?
Then, in the widget I would just return the rendered field collection item using that display mode. Drupal's internal field handling would then allow you to re-order or remove items. Not sure if we could turn off the 'add' button?
Any thoughts are welcome
Comment | File | Size | Author |
---|---|---|---|
#8 | field_collection-sort-only-widget-1995358-8.patch | 3.42 KB | james.williams |
Comments
Comment #1
erik.erskine CreditAttribution: erik.erskine commentedThis module may help - we have addressed a similar use case: https://drupal.org/sandbox/ingaro/2019853
Comment #2
Angry Dan CreditAttribution: Angry Dan commentedThanks erik_erskine! If the problem comes up again I'll be sure to take a look.
Not sure where that leaves this issue? Anything from the maintainer about the feature request?
Comment #3
erik.erskine CreditAttribution: erik.erskine commentedI've turned that sandbox module into a patch. It adds a new
field_collection_sorter
widget.Comment #4
guy_schneerson CreditAttribution: guy_schneerson commentedPatch #3 works great for me.
It allows users to use node view to add/edit/delete field collections and the node edit to sort them.
Comment #5
guy_schneerson CreditAttribution: guy_schneerson commentedOnly issue is the titles are numbered items and that makes it difficult to sort, not sure if this is an issue for this patch.
Comment #6
erik.erskine CreditAttribution: erik.erskine commentedUnlike nodes, field collection items don't have any obvious property to use
as a title, so the label shown in the widget will simply be something like
'Collection 1', Collection 2 etc. This comes from the entity's label()
method and is the same thing that's shown when the 'links to field collection
items' formatter is used.
You can change this for your own field collections where you know what the
fields are and have a means of picking a suitable title. You can implement
the following hook to load the field collection entity and replace the default
label with something more useful:
This problem with the lack of a node title crops up elsewhere see https://drupal.org/node/1335204 & https://drupal.org/node/1674298. We could do something clever to try to guess something meaningful, but I'm not sure it's within the scope of this patch though.
Comment #7
guy_schneerson CreditAttribution: guy_schneerson commentedWill give that a go, and thanks for the great patch.
Comment #8
james.williams CreditAttribution: james.williams commentedJust in case the field collection item has actually been deleted without updating the host entity, the attached patch avoids a fatal error, which is a bit over-kill for such a situation (which is possible when working with a variety of other modules, such as workbench).
Comment #9
Chris Matthews CreditAttribution: Chris Matthews commentedThe patch in #8 is 4 years old, but still applies cleanly to 7.x-1.x-dev and is a great improvement to this module. Can someone else review/test before RTBC?
Comment #11
ram4nd CreditAttribution: ram4nd as a volunteer commented