Problem/Motivation

#3525891: Add preferred_name field to Person Contact Type 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

Issue fork crm-3526904

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jdleonard created an issue. See original summary.

bluegeek9’s picture

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, #3194734: Translate name formats by language

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.

jdleonard’s picture

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 for that User when they're logged in
  • 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
bluegeek9’s picture

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();

jdleonard’s picture

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")

bluegeek9’s picture

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, #3194734: Translate name formats by language

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.

bluegeek9’s picture

There are issues with name and the search API:

#2908703: Search API full name field
#3378054: Search in Views

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.

bluegeek9’s picture

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

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.

bluegeek9’s picture

Assigned: Unassigned » bluegeek9
bluegeek9’s picture

I need to refactor the functional hook into a class.

  • bluegeek9 committed b5d6b583 on 1.0.x
    Issue #3526904 by bluegeek9: Customize display of contacts' names
    
bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
Status: Active » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triaging issues and adding more context to existing issues.
  • Flagging CRM as a favorite on the project page to help others discover it and show your support.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.