public function AvatarManager::findValidAvatar in Avatar Kit 8
Go down the the avatar generator preference hierarchy for a user.
Loads each avatar until a valid avatar is found.
Parameters
\Drupal\user\UserInterface $user: A user entity.
Return value
\Drupal\avatars\AvatarPreviewInterface|null An avatar preview entity.
Overrides AvatarManagerInterface::findValidAvatar
1 call to AvatarManager::findValidAvatar()
- AvatarManager::syncAvatar in src/
AvatarManager.php - Check user avatar for changes, and inserts the avatar into the user entity.
File
- src/
AvatarManager.php, line 128
Class
- AvatarManager
- Provides an avatar manager service.
Namespace
Drupal\avatarsCode
public function findValidAvatar(UserInterface $user) {
foreach ($this
->getPreferences($user) as $avatar_generator => $scope) {
$avatar_generator = $this->avatarGeneratorStorage
->load($avatar_generator);
if ($avatar_generator instanceof AvatarGeneratorInterface) {
$this
->refreshAvatarGenerator($user, $avatar_generator, $scope);
if ($avatar_preview = AvatarPreview::getAvatarPreview($avatar_generator, $user)) {
if ($avatar_preview
->getAvatar()) {
return $avatar_preview;
}
}
}
}
return NULL;
}