You are here

protected function ProfileEntityFieldItemList::getUserProfiles in Profile 8

Get the user's profiles.

Return value

array|\Drupal\profile\Entity\ProfileInterface[] An array of profiles.

2 calls to ProfileEntityFieldItemList::getUserProfiles()
ProfileEntityFieldItemList::computeValue in src/Plugin/Field/ProfileEntityFieldItemList.php
Computes the values for an item list.
ProfileEntityFieldItemList::referencedEntities in src/Plugin/Field/ProfileEntityFieldItemList.php
Gets the entities referenced by this field, preserving field item deltas.

File

src/Plugin/Field/ProfileEntityFieldItemList.php, line 39

Class

ProfileEntityFieldItemList
Represents a profile entity reference field.

Namespace

Drupal\profile\Plugin\Field

Code

protected function getUserProfiles() {
  $user = $this
    ->getEntity();
  assert($user instanceof UserInterface);

  /** @var \Drupal\profile\ProfileStorageInterface $profile_storage */
  $profile_storage = \Drupal::entityTypeManager()
    ->getStorage('profile');

  // Ignore anonymous and user accounts not saved yet.
  if ($user
    ->isAnonymous()) {
    return [];
  }
  $profiles = $profile_storage
    ->loadMultipleByUser($user, $this
    ->getSetting('profile_type'), TRUE);

  // This will renumber the keys while preserving the order of elements.
  $profiles = array_values($profiles);
  return $profiles;
}