Customize display of contacts' names

Created on 28 May 2025, 11 days ago

Problem/Motivation

πŸ“Œ Add nickname field to Individual Contact Type Active adds a preferred name / nickname field to the Individual Contact Type, but this field is not rendered anywhere e.g. as part of the Contact's label.

More generally, different end users of CRM will want Contacts' names to be output differently. For example, the Name module provides Western, German, Asian, etc. options for name output.

CRM should provide a mechanism for an end user to customize how Contacts' names are rendered in lists etc. and should provide some options OOTB to serve the common needs of end users globally.

Proposed resolution

Remaining tasks

Define the plan

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

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

Comments & Activities

  • Issue created by @jdleonard
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    The individual/person full_name should be able to render differently in a view. Rendering the field based on the viewer's language is in the backlog, ✨ Translate name formats by language Active

    The individual/person name field is a string and the format is chosen on save. All persons/individuals should have the same name format for consistency;

    The crm_user (crm_user_contact) allows the contact's name to be used for the user's display name. Maybe a name format field could be added to allow the user to select the format for their display name.

  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    I'm struggling to wrap my head around the various levels of indirection at play here, but let me try proposing an approach that provides maximum flexibility and seems easy enough to implement:

    • Provide some sensible name formats, catering to known name format preferences around the world (and accounting for preferred name)
    • Provide a CRM setting "Default contact name format" that lets the CRM admin select the default name format from the list of name formats for CRM functionality
    • Provide an optional "Contact name format" field on the Drupal User entity that overrides the Default contact name format
    • Scrap the name-related logic in Contact::preSave()
    • Implement Contact::label() to return the appropriately formatted value from the full_name field (using the User's Contact name format if set, otherwise the Default contact name format) in the case of an Individual and otherwise the value of the name base field
    • Remove the label key from Contact's entity_keys - superseded by the label() override
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    CRM Core implemented:

    • Implement Contact::label() to return the appropriately formatted value from the full_name field (using the User's Contact name format if set, otherwise the Default contact name format) in the case of an Individual and otherwise the value of the name base field
    • Remove the label key from Contact's entity_keys - superseded by the label() override

    It was bad. Because of the name field, autocomplete was unusable after a couple hundred contacts. Sorting was also an issue

    The current design is a response to that architecture.

    Provide an optional "Contact name format" field on the Drupal User entity that overrides the Default contact name format for that User when they're logged in

    This is not meant to override the contact's name. It overrides the user's name; $user->getDisplayName();

  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    Now I understand the current design :)

    It's more work, but I propose that we adopt Search API. This will be something commonly adopted for more intense use cases and it will benefit performance for the small ones too. Even the default database Search API backend (paired with a Search API Views-based autocomplete) would solve the autocomplete performance issue you describe CRM Core having faced, right?

    Provide an optional "Contact name format" field on the Drupal User entity that overrides the Default contact name format for that User when they're logged in

    I intended this as a User preference for how all Contacts' names should be rendered for that User ("I live in [country] and American name formats detract from a positive user experience")

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I intended this as a User preference for how all Contacts' names should be rendered for that User ("I live in [country] and American name formats detract from a positive user experience")

    This is an issue for the name backlog, ✨ Translate name formats by language Active

    The search API will not solve the problem. At best it will cover it up until a site builder does something custom.

    I am hesitant to adopt dependencies unless necessary.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    There are issues with name and the search API:

    #2908703: Search API full name field β†’
    πŸ’¬ Search in Views Active

    A sitebuilder can make an Entity Reference Display to make it look however they want. The contact.name is a static field that is easy to filter.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I created an issue for customizing the User's display name: ✨ User Display Name preference Active

    I think we should use the default name format for the Person's label. We could also add a global setting to use a different format.

Production build 0.71.5 2024