Skip to content
Browse files

Updated references to fos_user.profile.form to use factory service.

  • Loading branch information...
1 parent 92a144c commit 5df24428a1fafe3e870ee4cfd3b6df7c06cb3e4b @rafalwrzeszcz rafalwrzeszcz committed
Showing with 26 additions and 8 deletions.
  1. +25 −6 Controller/ProfileController.php
  2. +1 −2 DependencyInjection/SonataUserExtension.php
View
31 Controller/ProfileController.php
@@ -56,14 +56,33 @@ public function editAuthenticationAction()
throw new AccessDeniedException('This user does not have access to this section.');
}
- $form = $this->container->get('sonata_user_authentication_form');
- $formHandler = $this->container->get('sonata_user_authentication_form_handler');
+ $formFactory = $this->container->get('sonata_user_authentication_form_factory');
+ $form = $formFactory->createForm();
+ $form->setData($user);
- $process = $formHandler->process($user);
- if ($process) {
- $this->setFlash('fos_user_success', 'profile.flash.updated');
+ $request = $this->getRequest();
+ if ($request->isMethod('POST')) {
+ $form->bind($request);
- return new RedirectResponse($this->generateUrl('sonata_user_profile_show'));
+ if ($form->isValid()) {
+ /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
+ $userManager = $this->container->get('fos_user.user_manager');
+ /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
+ $dispatcher = $this->container->get('event_dispatcher');
+
+ $event = new FormEvent($form, $request);
+ $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
+
+ $userManager->updateUser($user);
+
+ if (null === $response = $event->getResponse()) {
+ $response = $this->redirect('sonata_user_profile_show');
+ }
+
+ $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
+
+ return $response;
+ }
}
return $this->render('SonataUserBundle:Profile:edit_authentication.html.twig', array(
View
3 DependencyInjection/SonataUserExtension.php
@@ -244,8 +244,7 @@ public function registerDoctrineMapping(array $config)
*/
public function configureShortcut(ContainerBuilder $container)
{
- $container->setAlias('sonata_user_authentication_form', 'fos_user.profile.form');
- $container->setAlias('sonata_user_authentication_form_handler', 'fos_user.profile.form.handler');
+ $container->setAlias('sonata_user_authentication_form_factory', 'fos_user.profile.form.factory');
}
/**

0 comments on commit 5df2442

Please sign in to comment.
Something went wrong with that request. Please try again.