Currently it appears only the title can be used as the entity label. The label method was introduced here: #2558143: Opt-out from optional base fields
Many custom entities don't need a title field but may have other suitable fields which can be used as the label. If there's already a way to do this in the UI then I've missed it completely. The Title property/field seems to be left over from the pre-entity node days and is entirely optional with entities. Entity Labels aren't (or shouldn't be) optional and are more flexible.
Somewhat related, but it could also be good for the ECK content list ( /admin/structure/eck/entity/entity_type ) to have a Label column instead of Title by default.
Could this be done on a per-bundle basis? For example, we could list all the fields of type "string" as potential candidates, as well as the title if it's enabled.
Comments
Comment #2
imclean CreditAttribution: imclean commentedComment #3
imclean CreditAttribution: imclean commentedComment #4
legolasboThis seems like a really sensible solution. Unfortunately I lack the time to work on this myself at the moment (baby due any moment), but I welcome any help in solving this issue.
Comment #5
imclean CreditAttribution: imclean commentedI don't have a lot of time either but hope I can still contribute something. This patch doesn't do much yet, it just adds the config option to the bundle edit form. It doesn't save properly either, I'm still learning about Drupal 8 and ECK.
Congrats on the baby legolasbo.
Comment #6
imclean CreditAttribution: imclean commentedComment #7
imclean CreditAttribution: imclean commentedThis adds the option to select the label field per bundle type, with fallback to current behaviour. It supports title and string fields as label fields.
Comment #8
imclean CreditAttribution: imclean commentedIt also changes the the header text in the ECK content list from "Title" to "Label". It already uses the label callback.
Comment #11
imclean CreditAttribution: imclean commentedTry again.
Comment #14
imclean CreditAttribution: imclean commentedMissed one.
Comment #15
legolasboThanks for your contribution imclean,
The patch looks promising, but I would like to see all added functionality under test before I commit it.
Comment #16
imclean CreditAttribution: imclean commentedI'm still getting up to speed with writing tests. What would need to be tested against here? I don't think there's currently a specific test for the label field and/or method. I've added the new config option.
Comment #17
legolasboI think you have answered your own question. There currently is no specific test for the label field and/or method, but there should be, so that's what needs to be tested.
Comment #18
imclean CreditAttribution: imclean commentedThis adds a check, first() isn't always needed. Still needs tests.
Comment #19
legolasboComment #22
imclean CreditAttribution: imclean commentedComment #23
imclean CreditAttribution: imclean commentedComment #24
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedThis is working for me, and IMO this is a pretty major issue for making ECK more versatile and usable in a wider variety of situations. About 1/2 of my entity types don't have a Title field, but do have another field I want to use for labeling.
Comment #25
legolasboRerolled the patch as it no longer applied to the latest head.
Comment #26
legolasboThis issue still needs test coverage for the new functionality.
While testing the patch manually I found that you can only use textfields as the label. In my opinion fields like date, list (text) or email could be valid labels as well.
Also looking at the code. I think you could replace
with
Comment #27
imclean CreditAttribution: imclean commentedI've added a few extra field types, not all have been tested yet. For some reason I couldn't create content if a date field was present but that's a separate issue.
Using
returned
NULL
.These 4 lines still work:
Comment #28
imclean CreditAttribution: imclean commentedStill needs tests. Different field types may need to be handled differently, although I'm not sure about this.
Comment #29
imclean CreditAttribution: imclean commented'text' is listed twice.
Comment #30
danharper CreditAttribution: danharper as a volunteer and at hrpr commentedPatch is failing on latest dev, is this something that is going to be turned into a stable feature?
Comment #31
imclean CreditAttribution: imclean commentedWe're not using ECK in any new projects so I'm unlikely to work on this.
Comment #32
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedHere is a reroll and refactor of some of the code in the previous patch. I went with an event to allow customization of the available field types since hardcoding it seemed too rigid.
I also removed the conditional checking for the "field_" prefix, because custom fields might not have that if they were created in code.
This is barely tested yet, but I needed to get a working version of the patch for the latest dev.
Comment #33
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedAdding a related issue, which might also be the one making this patch no longer apply. They aren't solving the same thing, but they are solving similar things related to customizing the label.
Comment #34
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedAttempting a reroll against the latest dev. Let's see how well this works.
Comment #35
JLucySong CreditAttribution: JLucySong at Northern Commerce commentedThanks bmcclure
Somehow the label field setting is not always saved successfully
It's still showing the default title instead of the custom field
Comment #36
danharper CreditAttribution: danharper as a volunteer and at hrpr commentedSlightly off topic
If anybody is looking for a quick way to solve this I used https://www.drupal.org/project/auto_entitylabel
1. Install above module
2. Enable title for entity type
3. Configure title to be auto generated with tokens and hidden from display.|
Thanks Dan
Comment #37
RichardGaunt CreditAttribution: RichardGaunt commentedI've re-rolled against latest release (beta 2) in case anyone needs.
Comment #38
RichardGaunt CreditAttribution: RichardGaunt commentedAlso, re-rolled against latest dev version.
Comment #39
RichardGaunt CreditAttribution: RichardGaunt commentedCan also report that the custom label configuration is not reliably being saved. I'll investigate if I get a chance.
Comment #40
DieterHolvoet CreditAttribution: DieterHolvoet at Minsky commentedReplaced
\Drupal::entityManager()
with$this->entityFieldManager
.Comment #41
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commenteduse short array syntax as per new coding standard.
Comment #42
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #43
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound for Valuebound commentedNeeds work
Comment #44
dqdHaven't scrolled the issue yet but please keep an eye on the core and AEL issues raising and getting progress regarding base fields. I think it is important to sync overlapping efforts here.
Too many to link them all here but some out of my head:
#3088103: Entity label (title) field shouldn't be a base field but a required option to choose a field for.
#2353867: [META] Expose Title and other base fields in Manage Display
#3043592: Allow entity to display label field as normal
#2877400: Find a way to make title handling generic in entity templates