Entity label (title) field shouldn't be a base field but a required option to choose a field for.

Created on 15 October 2019, over 5 years ago
Updated 23 January 2024, about 1 year ago

Problem/Motivation

As a follow-up on some discussion(s) we already had in the last years about how to deal with the hard coded view of the misleading named "title" (entity label) base field on entities and the already running [META] issue working around some of the issues with it, I came to a possible worth-to-discuss idea I can't find a duplicate issue or META for yet in the issue queues. To not "work around" it, but to make it conceptually clearer and more useful in the sense why we had this base field and why it was required.

Users more often than expected think that they actually do not need a mandatory (required) entity type > label (f.e. "title") field in all use-cases, so that we always had a hard time to explain why we still "need" it for many reasons (e.g. referencing). But what is it what we do need on it exactly? Reading all the issues discussing this aspect makes clear that there is something upsidedown: We rather need a field serving as a label instead of a label serving as a base field (Look at Paragraphs or ECK). What I mean by that is, that no additional base field is needed, but a mandatory choice to make which field will serve as the label with the label functionality combined, for a given field already setup for this entity type. This prevents having additional and sometimes meaningless label fields around on created entity types.

Proposed resolution

In my understanding of content modeling by fields (which is somewhat similar to data modeling in general in many of the visible aspects) a fixed field type namely "label" is actually not a usual mandatory base field, like unique node_id is, or like date_created or date_modified or authored_by is. I think it was a work around to have something "readable" in place serving as label? We rather should give the option at hand to choose a proper field type (depends on the use case) in the entity type creation form as a "label" for the entity/content type instead. And we should explain in the description of the checkbox/radio why this is mandatory and required to choose one of the fields created on the entity type to serve as label.

As an example: The content type "Article" in the default Drupal installation profile could show some "headline" field with a ticked checkbox "use as label" to demonstrate how it works, which can be changed/reversed by the user (but only as long as no content or reference has been created).

This would solve so many issues with the entity type label base field conceptually and would stop confuse users in so many use cases, that I cannot stop thinking about it. Even if it makes no sense or has issues which make it impossible to realize this idea. (Let me know please).

This way the required readable "label" of any entity type like content type isn't a fixed base field no more, but it is a required choice to make (setup to make) and an additional title/label field misused as base field isn't needed no more. Any proper field type already set up for this bundle can serve as the label, e.g. on references or automatic listings, etc. And contributed module projects like "Automatic entity label" or "Unique title field" aren't required no more since we do have already projects on D.O. checking unique field values or autofill fields from Tokens or Twig variables (but not for the label).

The same goes for the "name" field on the media entity types or the "title" in custom blocks. We should leave it to the user to choose a proper field type as the readable β€œlabel” for it and should make a radio / checkbox "use as label" in the field creation form or similar available. The flexibility raising from it would be endless.

Remaining tasks

  • Relate all entity type label issues of core and try to compare all made suggestions and solutions against it.
  • Discuss if this is even possible and realisticly providable from the way "how entity types work".
  • Show use cases demonstrating the urgency of this idea to discuss, if so.
  • Show work arounds users could do to achieve this without core changes and possible drawbacks.

User interface changes

Some field type creation forms will have an additional checkbox/radio, like "use as label" which can only be ticked once in a entity type creation form.

API changes

Maybe this requires also API changes since we maybe run hooks against the former base field "label" on several places?

Data model changes

There will be no base field serving as label no more, but a choosen existing field in the created entity type serving as "label".

NOTE: I am not sure if it possible to run such a change in an experimental version, since the change is too drastic in the whole installation.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    To get this issue out of its theoretical state and to put first concrete possible changes to be made on the table:

    As we can see in the active issue queue regarding references and reference form field widgets (I saw them coming ;-) this is an issue on a huge scale and that is the reason why my OT was so long. :-) In case we go that route proposed here to make any field created on that entity bundle type available to choose as the label we need also to consider another way we internally check for the choosen label field. Because we can not know OOTB which one it is. The choosen label field need to have an own "type register" where to look at for fields choosen as label on that bundle, which brings in a complete new way for reference form fields to fetch or display or select on lists etc.

  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

    This issue remains hard to understand, many words but few technical details.

    The label is defined in 2 places AFAIK:
    (1) the label() method on an entity, which is overriddable by swapping out the entity class or bundle class.
    (2) The label key on the entity type annotation which is shared between all bundles of an entity type. It provides the default user by the label() method, as well as being used in queries like autocomplete queries.

    So if there is a feature request here, it sounds like either:
    (1) make entity keys (or at least the label key) overriddable at the bundle level
    (2) provide a UI for configuring the label on a bundle

    Probably (2) depends on (1) anyway.

    (1) profoundly changes assumptions about the data structure of Drupal entities. To ensure BC we would have to replace the getEntityKey() method with a getBundleKey() or at least add the latter. And this leads to complications - possibly insurmountable - when querying across multiple bundles.

    Fundamentally I think this issue is wrongly targeted. Its focus should be on making it easier for entity autocomplete in particular to query across fields other than the entity label. The problem is not the entity label data structure, it's with autocomplete's narrow focus on the label.

  • πŸ‡³πŸ‡ΏNew Zealand john pitcairn

    Is this about entity reference field autocomplete?

    If so, what's wrong with the established technique of using a view to provide the entity suggestions. That does allow you to specify the entity fields to search on.

  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

    You're right. So my retitling was a mistake.

    We can already specify any field we like to be the label, so the IS is misleading.

    The feature request here has to be: Allow entity keys to be definable/overriddable per bundle per #25.

    But this is a big change in the architectural model for a small gain, so I have to think we should close as won't fix.

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Thanks for joining. There are many possibilities for misunderstanding. Also on my side for sure. But please do not change the title immediately from your POV without discussion what this is about here. The OT summary is too long as already discussed earlier and I was about to change that while this issue now feels slidely hijacked and from the original purpose more and more drifting. All your good ideas regarding "what it possibly means technically to change for that" are possibly right and maybe part of follow ups (tasks). But this issue needs some work on the OT from the original poster before we can discuss its tasks or possible confusions in it. Sorry that I missed no comment that I am already working on the OT summary

    Best points until now have been made in #13 and #14 so far.

  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK
    The other way is to not rely on one special field created only for that purpose, but relying on a flag on a field stating that this field is the label now, as explained multiple times above in other words.

    This is already the case. The 'label' key in the entity keys section of the entity annotation defines which basefield is the label. There is no requirement to create a basefield specifically for the purpose of being the label.

    For example, the title field is the label field for the node entity, the id field could perfectly well be the label.

    /**
     * Defines the node entity class.
     *
     * @ContentEntityType(
     *   id = "node",
    ...
     *   entity_keys = {
     *     "id" = "nid",
     *     "revision" = "vid",
     *     "bundle" = "type",
     *     "label" = "title",
    ...
     *   },
    ...
     * )
     */
    class Node extends EditorialContentEntityBase implements NodeInterface {
    

    I am not clear from the comments in this issue what about this is insufficient.

    The way the current approach is architected means the selected field must be a basefield, it cannot be a diffrent field on each bundle, such as a configurable field. If this is the concern, then the feature request here seems to boil down to: Allow entity keys to be definable/overriddable per bundle.

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    We can already specify any field we like to be the label, so the IS is misleading.

    The OT ist not "misleading". The starting date of the issue is some years ahead. Maybe I missed something lately which makes the whole issue already obsolete.

    @ #29: Thanks for trying to clarify your thoughts. As stated above (before): I will investigate in the next spare time on possible misunderstandings and on sharpening the idea discussed here. Plus: There is a big chance that I am not aware of that this issue already run far out of date.

  • Status changed to Closed: outdated 4 months ago
  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Many things have changed over the years already. And the standard install profile of Drupal core - which was somewhat unspokenly the basis of this issue attempt - will maybe become less important in the near future. Especially with the starshot initiative getting momentum. So, many of the thoughts in here can be considered outdated. Or rather "absorbed". In a positive way.

    To clarify: Most of the misunderstandings in here in between were mainly caused by the fact that the IS tries to cover the "no-code" impressions from average users UI perspective on a standard install profile. While some participations on the disucssion are referring to ways to change that in code or non standard profile scenarios, f.e. custom entities and such.

    Misleading or not, maybe too non-technical in some aspects, also, yes, and last but not least too theoretical and mostly based on the assumption, that users are rather familiar with creating node types and fields on node types like provided in the standard profile, the idea behind all this has been somewhat absorbed already in different evolutions of the whole Drupal concept and eco system over the years. Users get more and more used to custom entities and the understanding of fields, base fields and labels are evolved.

    So, after thinking about it for a while now if it makes sense to invest more time in here to clarfiy or narrow the idea into a more understandable concept, while parts of it are already "fixed" in other ways, I came to the conclusion to close this issue as outdated.

    In case some of it could need further discussion it would rather make more sense to create a new issue to prevent wasted efforts of users reading all of the previously obsolete content.

Production build 0.71.5 2024