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
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
Comment #2
bluegeek9 commentedThe 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.
Comment #3
jdleonardI'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:
Contact::preSave()Contact::label()to return the appropriately formatted value from thefull_namefield (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 thenamebase fieldlabelkey from Contact'sentity_keys- superseded by thelabel()overrideComment #4
bluegeek9 commentedCRM Core implemented:
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.
This is not meant to override the contact's name. It overrides the user's name; $user->getDisplayName();
Comment #5
jdleonardNow 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?
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")
Comment #6
bluegeek9 commentedThis 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.
Comment #7
bluegeek9 commentedThere 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.
Comment #8
bluegeek9 commentedI 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.
Comment #9
bluegeek9 commentedComment #10
bluegeek9 commentedI need to refactor the functional hook into a class.
Comment #13
bluegeek9 commented