Reputation: 5074
I'm trying to perform several operations for every new registred user, so the first thing that corsses my mind is evnets. Unfortunately, I figured out that registration events don't exist for the version 1.3.x (there isn't any folder called events in there). And here's the master version: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/FOSUserEvents.php
What's the easiest thing I should do?
Upvotes: 0
Views: 374
Reputation: 470
Upgrade to 2.0 version is not an option I assume? I'm looking at the same problem, as I don't want to upgrade because SonataAdmin isn't really ready for it yet: https://github.com/sonata-project/SonataUserBundle/issues/322.
As the 1.3.x version doesn't have events, depending on what you need you could either just extend the controller and override what you need changed, or if you want more control over the forms you could create your formType or handler and inject those into the FOSUserBundle:
namespace MyVendor\MyBundle\Form\Handler;
use FOS\UserBundle\Form\Handler\RegistrationFormHandler as BaseRegistrationFormHandler;
class RegistrationFormHandler extends BaseRegistrationFormHandler
{
protected function createUser()
{
$user = $this->userManager->createUser();
$user->addRole("ROLE_USER_PRO");
$user->setUsername("generate a value here");
$user->setPlainPassword("also a generated value");
return $user;
}
Then tell FOSUser to use your special handler (you have to declare the above as a new service):
fos_user:
registration:
form:
handler: mybundle.registration.form.handler
Upvotes: 1