You are here

public function ProfileStorage::loadByUser in Profile 8

Loads the given user's profile.

Takes the default profile, if found. Otherwise falls back to the newest published profile.

Primarily used for profile types which only allow a single profile per user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user.

string $profile_type_id: The profile type ID.

Return value

\Drupal\profile\Entity\ProfileInterface|null The profile. NULL if no matching entity was found.

Overrides ProfileStorageInterface::loadByUser

File

src/ProfileStorage.php, line 33

Class

ProfileStorage
Defines the entity storage for profile.

Namespace

Drupal\profile

Code

public function loadByUser(AccountInterface $account, $profile_type_id) {
  $query = $this
    ->getQuery();
  $query
    ->condition('uid', $account
    ->id())
    ->condition('type', $profile_type_id)
    ->condition('status', TRUE)
    ->sort('is_default', 'DESC')
    ->sort('profile_id', 'DESC')
    ->range(0, 1)
    ->accessCheck(FALSE);
  $result = $query
    ->execute();
  return $result ? $this
    ->load(reset($result)) : NULL;
}