You are here

public function AvatarManager::getAvatarGeneratorsForUser in Avatar Kit 8

Gets a lit of active plugins a user has permission to use.

Parameters

\Drupal\user\UserInterface $user: A user entity.

bool $exclude_user_preference: Exclude 'user preference' plugin types.

Return value

\Drupal\avatars\AvatarGeneratorInterface[]|\Generator An array of avatar generator entities.

Overrides AvatarManagerInterface::getAvatarGeneratorsForUser

2 calls to AvatarManager::getAvatarGeneratorsForUser()
AvatarManager::getPreferences in src/AvatarManager.php
Avatar preference generators.
AvatarManager::refreshAllAvatars in src/AvatarManager.php
Downloads all avatar previews for a user.

File

src/AvatarManager.php, line 277

Class

AvatarManager
Provides an avatar manager service.

Namespace

Drupal\avatars

Code

public function getAvatarGeneratorsForUser(UserInterface $user, $exclude_user_preference = TRUE) {
  $avatar_generators = [];
  foreach ($this->avatarGeneratorStorage
    ->getEnabledAvatarGenerators() as $avatar_generator) {
    if ($avatar_generator
      ->getPlugin()
      ->getPluginId() == 'user_preference') {
      if ($exclude_user_preference) {
        continue;
      }
    }
    elseif (!$user
      ->hasPermission("avatars avatar_generator user " . $avatar_generator
      ->id())) {
      continue;
    }
    $avatar_generators[] = $avatar_generator;
  }
  return $avatar_generators;
}