public function AvatarManager::getPreferences in Avatar Kit 8
Avatar preference generators.
Ordered by priority.
Parameters
\Drupal\user\UserInterface $user: A user entity.
Return value
\Generator Generator yield pairs: key: string $avatar_generator_machine_name value: value of constants prefixed with AvatarPreviewInterface::SCOPE_*
Overrides AvatarManagerInterface::getPreferences
1 call to AvatarManager::getPreferences()
- AvatarManager::findValidAvatar in src/
AvatarManager.php - Go down the the avatar generator preference hierarchy for a user.
File
- src/
AvatarManager.php, line 233
Class
- AvatarManager
- Provides an avatar manager service.
Namespace
Drupal\avatarsCode
public function getPreferences(UserInterface $user) {
$avatar_generators = $this
->getAvatarGeneratorsForUser($user, FALSE);
uasort($avatar_generators, '\\Drupal\\avatars\\Entity\\AvatarGenerator::sort');
foreach ($avatar_generators as $avatar_generator) {
$id = $avatar_generator
->id();
if ($avatar_generator
->getPlugin()
->getPluginId() == 'user_preference') {
$id = $user->{AK_FIELD_AVATAR_GENERATOR}->value;
$scope = AvatarPreviewInterface::SCOPE_USER_SELECTED;
}
else {
$scope = AvatarPreviewInterface::SCOPE_SITE_FALLBACK;
}
// Catches empty user preference.
if ($id) {
(yield $id => $scope);
}
}
}