src/EventSubscribers/ProfileEditSubscriber.php line 53

  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: ashishranpara
  5.  * Date: 24/05/18
  6.  * Time: 5:34 PM
  7.  */
  8. namespace App\EventSubscribers;
  9. use FOS\UserBundle\Event\FormEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. use FOS\UserBundle\FOSUserEvents;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. /**
  15.  * Event Listener to change redirection after password change successfully.
  16.  *
  17.  * Class ChangePasswordListener
  18.  * @package App\EventListeners
  19.  */
  20. class ProfileEditSubscriber implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var UrlGeneratorInterface
  24.      */
  25.     private $router;
  26.     /**
  27.      * ChangePasswordListener constructor.
  28.      * @param UrlGeneratorInterface $router
  29.      */
  30.     public function __construct(UrlGeneratorInterface $router)
  31.     {
  32.         $this->router $router;
  33.     }
  34.     /**
  35.      * @return array
  36.      */
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [
  40.             FOSUserEvents::CHANGE_PASSWORD_SUCCESS => 'onPasswordResettingSuccess',
  41.             FOSUserEvents::PROFILE_EDIT_SUCCESS => 'onProfileEditSuccess'
  42.         ];
  43.     }
  44.     /**
  45.      * @param FormEvent $event
  46.      */
  47.     public function onPasswordResettingSuccess(FormEvent $event)
  48.     {
  49.         $url $this->router->generate('fos_user_change_password');
  50.         $event->setResponse(new RedirectResponse($url));
  51.     }
  52.     /**
  53.      * @param FormEvent $event
  54.      */
  55.     public function onProfileEditSuccess(FormEvent $event)
  56.     {
  57.         $url $this->router->generate('fos_user_profile_edit');
  58.         $event->setResponse(new RedirectResponse($url));
  59.     }
  60. }