function social_profile_fields_social_user_name_display_suggestions in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 8.5 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 8.6 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 8.7 modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 10.3.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 10.0.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 10.1.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
- 10.2.x modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.module \social_profile_fields_social_user_name_display_suggestions()
Implements hook_social_user_name_display_suggestions().
Adds the nickname as a possible display name.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
social_features/ social_profile/ modules/ social_profile_fields/ social_profile_fields.module, line 53 - The social profile fields module file.
Code
function social_profile_fields_social_user_name_display_suggestions(AccountInterface $account) : array {
$suggestions = [];
/** @var \Drupal\profile\ProfileStorageInterface $storage */
$storage = \Drupal::entityTypeManager()
->getStorage('profile');
if (!($user_profile = $storage
->loadByUser($account, 'profile', TRUE))) {
return $suggestions;
}
if (_social_profile_fields_get_setting('profile_profile_field_profile_nick_name') && !$user_profile->field_profile_nick_name
->isEmpty()) {
// Add the nickname with a low weight so it's shown before the full name.
$suggestions['nickname'] = [
'weight' => -100,
'name' => $user_profile->field_profile_nick_name->value,
];
}
return $suggestions;
}