3 namespace Wallabag\UserBundle\EventListener
;
5 use Doctrine\ORM\EntityManager
;
6 use FOS\UserBundle\Event\UserEvent
;
7 use FOS\UserBundle\FOSUserEvents
;
8 use Symfony\Component\EventDispatcher\EventDispatcherInterface
;
9 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
10 use Wallabag\CoreBundle\Entity\Config
;
13 * This listener will create the associated configuration when a user register.
14 * This configuration will be created right after the registration (no matter if it needs an email validation).
16 class CreateConfigListener
implements EventSubscriberInterface
23 private $readingSpeed;
25 public function __construct(EntityManager
$em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed)
28 $this->theme
= $theme;
29 $this->itemsOnPage
= $itemsOnPage;
30 $this->rssLimit
= $rssLimit;
31 $this->language
= $language;
32 $this->readingSpeed
= $readingSpeed;
35 public static function getSubscribedEvents()
38 // when a user register using the normal form
39 FOSUserEvents
::REGISTRATION_COMPLETED
=> 'createConfig',
40 // when we manually create a user using the command line
41 // OR when we create it from the config UI
42 FOSUserEvents
::USER_CREATED
=> 'createConfig',
46 public function createConfig(UserEvent
$event, $eventName = null, EventDispatcherInterface
$eventDispatcher = null)
48 $config = new Config($event->getUser());
49 $config->setTheme($this->theme
);
50 $config->setItemsPerPage($this->itemsOnPage
);
51 $config->setRssLimit($this->rssLimit
);
52 $config->setLanguage($this->language
);
53 $config->setReadingSpeed($this->readingSpeed
);
55 $this->em
->persist($config);