You are here

function hook_social_user_name_display_suggestions in Open Social 8.9

Same name and namespace in other branches
  1. 8.5 modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  2. 8.6 modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  3. 8.7 modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  4. 8.8 modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  5. 10.3.x modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  6. 10.0.x modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  7. 10.1.x modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()
  8. 10.2.x modules/social_features/social_user/social_user.api.php \hook_social_user_name_display_suggestions()

Add suggestions for finding a suitable display name for the user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The account to add display name suggestions for.

Return value

array[] An array of suggestions with machine name keys. Each suggestion must have at least a 'name'. The 'name' entry will be displayed to the user. An optional 'weight' field can be added to the suggestion to control the priority of the suggestion. 'weight' defaults to 0 if not specified.

2 functions implement hook_social_user_name_display_suggestions()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

social_profile_fields_social_user_name_display_suggestions in modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module
Implements hook_social_user_name_display_suggestions().
social_profile_social_user_name_display_suggestions in modules/social_features/social_profile/social_profile.module
Implements hook_social_user_name_display_suggestions().
1 invocation of hook_social_user_name_display_suggestions()
social_user_user_format_name_alter in modules/social_features/social_user/social_user.module
Implements hook_user_format_name_alter().

File

modules/social_features/social_user/social_user.api.php, line 203
Hooks provided by the Social_user module.

Code

function hook_social_user_name_display_suggestions(AccountInterface $account) : array {
  $suggestions = [];

  // Add a fallback to display when no other suggestions are available.
  $suggestions['fallback'] = [
    'weight' => 1000,
    'name' => 'Name hidden',
  ];
  switch ($account
    ->id()) {
    case 1:

      // Show our admin user the respect she deserves.
      $suggestions['respect_admin'] = [
        'weight' => -1000,
        'name' => 'Jane Almighty',
      ];
      break;
    case 0:

      // Change the name of anonymous users.
      $suggestions['anonymous_alter'] = [
        // Default to weight => 0.
        'name' => 'Guest',
      ];
      break;
  }
  return $suggestions;
}