private function injectData() { $requestUser = $this->requestStack->getCurrentRequest()->attributes->get('user'); if ($requestUser) { $userProfile = $requestUser->getId(); } else { $userProfile = $this->user; } $entity = $this->entityManager->getRepository('SnoozitUserBundle:User')->find($userProfile); if (!$entity) { throw new EntityNotFoundException("Ce profile n'existe pas."); } $userProfileComment = new UserProfileComment(); $userProfileComment->setUserProfile($entity); $userProfileComment->setUser($this->user); return $this->form->setData($userProfileComment); }