public function AvatarManager::syncAvatar in Avatar Kit 8
Check user avatar for changes, and inserts the avatar into the user entity.
Parameters
\Drupal\user\UserInterface $user: A user entity.
Overrides AvatarManagerInterface::syncAvatar
File
- src/
AvatarManager.php, line 108
Class
- AvatarManager
- Provides an avatar manager service.
Namespace
Drupal\avatarsCode
public function syncAvatar(UserInterface $user) {
if ($user
->isAnonymous()) {
return;
}
$field_item_list =& $user->{AK_FIELD_PICTURE_ACTIVE};
$file1 = isset($field_item_list->entity) ? $field_item_list->entity : NULL;
$avatar_preview = $this
->findValidAvatar($user);
$file2 = $avatar_preview ? $avatar_preview
->getAvatar() : NULL;
if ($file1 !== $file2) {
$user->{AK_FIELD_PICTURE_ACTIVE} = $file2;
$user
->save();
}
}