You are here

function social_user_export_first_name in Open Social 8.2

Returns first name of user.

Parameters

\Drupal\user\UserInterface $account: The account to get the data for.

Return value

string Returns first name of the use.

1 call to social_user_export_first_name()
ExportUser::exportUserOperation in modules/social_features/social_user_export/src/ExportUser.php
Callback of one operation.

File

modules/social_features/social_user_export/social_user_export.module, line 98
The Social User Export module.

Code

function social_user_export_first_name(UserInterface $account) {
  $first_name = '';

  /** @var \Drupal\profile\ProfileStorageInterface $storage */

  // Check if entity type 'profile' exists.
  try {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('profile');
    if (!empty($storage)) {
      if ($user_profile = $storage
        ->loadByUser($account, 'profile', TRUE)) {
        $first_name = $user_profile
          ->get('field_profile_first_name')->value;
      }
    }
  } catch (InvalidPluginDefinitionException $e) {
    $first_name = '';
  }
  return $first_name;
}