getUser(); // create a form for password_encoder $form = $this->passwordForm($user); // process the form $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $password = $form->getData()->getPassword(); // logging for prod $this->get('logger')->info('update password for an user', array('method' => __METHOD__, 'user' => $user->getUsername())); $user->setPassword($this->get('security.password_encoder') ->encodePassword($user, $password)); $em = $this->getDoctrine()->getManager(); $em->flush(); $this->addFlash('success', $this->get('translator')->trans('Password successfully updated!')); } // render into a template return $this->render('ChillMainBundle:Password:password.html.twig', array( 'form' => $form->createView() )); } /** * * * @param User $user * @return \Symfony\Component\Form\Form */ private function passwordForm(User $user) { return $this->createForm(UserPasswordType::class, $user, array( 'method' => 'PUT', )) ->add('submit', SubmitType::class, array('label' => 'Change password')) ; } }