Is there any way to have field collections use an included field as the entity label?
My ultimate goal is to be able to reference field collections on a different content type, then let the two things share some information between eachother (for example, letting a content type "project" read a quantity field on a "publications" type that contains field collections).
Right now field collections DO work with entity reference, but there's no label set, so entityreference gives an unusable list of the collection name followed by a number.
IE:
collection 1
collection 2
collection 3
collection 1
collection 2
collection 3
collection 4
I'm not familiar with the entity API enough to make this change myself. If there's no way to do this, if you can point me to the right section of code I'll try my darndest to submit a patch. This is a GREAT module, it just has some rough patches integrating with other things.
Thanks,
Patrick
Comments
Comment #1
maxheight CreditAttribution: maxheight commentedI'm having the exact same issue.
Anyone have a solution?
Comment #2
Dean Reilly CreditAttribution: Dean Reilly commentedThere is a noted todo in the code to allow users to customise the entity label. I ran into it recently and started to do some work on it. I've removed the custom label callback that's currently being used and added in a label field to the entity (similar to the node module). This allows the user to set an entity label when filling out the form.
This may not seem very helpful, but once it's set up this way you can use the Automatic Entity Label module to generate the label based on field values or host entity field values.
There's still some work to do though:
Comment #3
Dean Reilly CreditAttribution: Dean Reilly commentedOops, wrong patch in that last comment. Try this one.
Comment #4
Dean Reilly CreditAttribution: Dean Reilly commentedThe upgrade will fail with that last patch as I made a mistake with one of the variables. This patch corrects the problem.
Comment #5
chrisschaub CreditAttribution: chrisschaub commentedTesting, this works well. Vote for commit.
Comment #6
chrisschaub CreditAttribution: chrisschaub commentedComment #7
tim.plunkettThis should have {} around the table name, and start with "Adds"
This whole function should be in the file after 7000
It's not clear to me, but why is this removed? Is the new label required now?
What is this? Can we have a comment about it?
Missing a trailing full stop.
Comment #8
kyleoliveira CreditAttribution: kyleoliveira commentedHas there been any movement on this? I would definitely like the ability to override the name of my Field Collection Items and this seems like an easy way to go about it.
Comment #9
purplezephyr CreditAttribution: purplezephyr commentedFixed several bugs in this patch, it should work now.
-didn't handle missing label correctly
-didn't work with auto_entitylabel because auto_entitylabel_form_alter() was being called before this patch called it; I used a brute-force solution, but it's probably not the right way to do it
-there is already a field_collection_update_7001(); moved to 7003 and the end of the file
Comment #10
purplezephyr CreditAttribution: purplezephyr commentedComment #12
purplezephyr CreditAttribution: purplezephyr commentedNot sure why that failed, maybe because I left out the diff command? Resubmitting with the command, against the dev branch...
Comment #14
purplezephyr CreditAttribution: purplezephyr commentedMeanwhile, here is an example of how to use auto_entitylabel and field_collection together, including the title of the containing node in the label of the field collection. Hopefully it will help anyone in the same situation. It does take a bit of tweaking for field names, entity types, etc.
Comment #15
purplezephyr CreditAttribution: purplezephyr commentedI think it needed to be in git format, trying again.
Also, an improvement to the the first line of that code sample:
Comment #17
purplezephyr CreditAttribution: purplezephyr commentedStill don't know what the issue was with the patch, but here is a version that bumps the database update number (because the latest dev version has a 7003 already).
Comment #18
lpalgarvio CreditAttribution: lpalgarvio commentedan idea: expose title/label field so that Title module can leverage it
https://drupal.org/project/title
Comment #19
KeyboardCowboyI took a different approach with this and added a hook to allow modules to customize the label of an item without requiring extra database fields. Apply this patch then you can simple implement this hook in a manner like:
Comment #21
meb CreditAttribution: meb commented#19 works for me. The approach works well for my needs. Thanks!
Comment #22
kristofferwiklund CreditAttribution: kristofferwiklund commentedWorks great. Thanks
Comment #25
jmuzz CreditAttribution: jmuzz commentedThanks @KeyboardCowboy, #19 committed.
It would still be nice to have an option to do it with the admin interface. The other patch might work if it is made to diff the files with themselves instead of with the *.orig versions which won't exist on the test server.