/** * Get the UserProfile from the current security user. * Reload UserProfile from the db when $reload = true * * @param bool $reload * * @return null|UserProfile */ public function getCurrentUserProfile($reload = false) { $user = $this->securityContext->getToken()->getUser(); if ($user instanceof User) { // check if there is no profile record for the user if (!($userProfile = $user->getUserProfile())) { $userProfile = new UserProfile(); $userProfile->setUser($user); $userProfile->setFirstName($user->getUsername()); $userProfile->setCountryId(Country::UNKNOWN); $userProfile->save(); } } else { return null; } if ($reload) { $user = $this->userRepository->findOneById($userProfile->getId()); $userProfile = $user->getUserProfile(); } return $userProfile; }