User Display Name preference

Created on 7 June 2025, about 6 hours ago

Problem/Motivation

Users mapped to a contact can use the contact's full name as their Display Name. User will want to control how thier name is formatted.

Steps to reproduce

Proposed resolution

Add a form element to the user's edit page to select a name format.
The value will be stored in user_data

If no format is select we can either:
have a setting in crm.user.settings for the default format
,or
User the contact's label

Remaining tasks

User interface changes

API changes

This is the existing code.

/**
 * Implements hook_user_format_name_alter().
 */
function crm_user_format_name_alter(&$name, AccountInterface $account) {
  $override = \Drupal::config('crm.crm_user.settings')->get('display_name');
  if (!$override) {
    return;
  }

  $crm_users = \Drupal::entityTypeManager()
    ->getStorage('crm_user')
    ->loadByProperties(['user' => $account->id()]);

  if ($crm_users != NULL) {
    $crm_user = reset($crm_users);
    $name = $crm_user->getContact()?->label();
  }

}

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bluegeek9

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

Comments & Activities

Production build 0.71.5 2024