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 commentedComment #3
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 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 commentedComment #7
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 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 commentedTry again.
Comment #14
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 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 commentedThis adds a check, first() isn't always needed. Still needs tests.
Comment #19
legolasboComment #22
imclean commentedComment #23
imclean commentedComment #24
replicaobscuraThis 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 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 commentedStill needs tests. Different field types may need to be handled differently, although I'm not sure about this.
Comment #29
imclean commented'text' is listed twice.
Comment #30
danharper commentedPatch is failing on latest dev, is this something that is going to be turned into a stable feature?
Comment #31
imclean commentedWe're not using ECK in any new projects so I'm unlikely to work on this.
Comment #32
replicaobscuraHere 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
replicaobscuraAdding 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
replicaobscuraAttempting a reroll against the latest dev. Let's see how well this works.
Comment #35
JLucySong 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 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 commentedI've re-rolled against latest release (beta 2) in case anyone needs.
Comment #38
richardgaunt commentedAlso, re-rolled against latest dev version.
Comment #39
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 commentedReplaced
\Drupal::entityManager()with$this->entityFieldManager.Comment #41
Munavijayalakshmi commenteduse short array syntax as per new coding standard.
Comment #42
Munavijayalakshmi commentedComment #43
Munavijayalakshmi 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
Comment #45
dieterholvoet commentedI don't think this is an ideal solution to the problem. By requiring to select a field and using the raw string value of that field as label, you exclude the possibility of using fields that require some kind of formatting before being used as a label, like for example date fields. I'm inclined to close this as won't fix: the
titlefield as it exists now is good for most use cases, the Automatic Entity Label module can be used for more complex use cases. If we really were to go for this solution, I wouldn't allow to select date fields, otherwise it'll only be a matter of time before people start to ask how to change the date format.