src/Controller/Backend/UserEditController.php
/**
     * This function is called by add and edit function if given form was submitted and validated correctly.
     * Here the User Object will be persisted to the DB. A security exception will be raised if the roles
     * for the user being saved are not allowed for the current logged user.
     */
This function is called by add and edit function if given form was submitted and validated correctly.
Here the User Object will be persisted to the DB. A security exception will be raised if the roles
for the user being saved are not allowed for the current logged user.
This function is called by add and edit function if given form was submitted and validated correctly . Here the User Object will be persisted to the DB . A security exception will be raised if the roles for the user being saved are not allowed for the current logged user .
private function handleValidFormSubmit(FormInterface $form): void
    {
        $user = $form->getData();
        if ($user->getPlainPassword()) {
            $user->setPassword($this->passwordHasher->hashPassword($user, $user->getPlainPassword()));
            $user->eraseCredentials();
        }
        $event = new UserEvent($user);
        $this->dispatcher->dispatch($event, UserEvent::ON_PRE_SAVE);
        $this->em->persist($user);
        $this->em->flush();
        $event = new UserEvent($user);
        $this->dispatcher->dispatch($event, UserEvent::ON_POST_SAVE);
        $this->addFlash('success', 'user.updated_profile');
    }
private function handleValidFormSubmit ( FormInterface $ form ) : void { $ user = $ form -> getData ( ) ; if ( $ user -> getPlainPassword ( ) ) { $ user -> setPassword ( $ this -> passwordHasher -> hashPassword ( $ user , $ user -> getPlainPassword ( ) ) ) ; $ user -> eraseCredentials ( ) ; } $ event = new UserEvent ( $ user ) ; $ this -> dispatcher -> dispatch ( $ event , UserEvent :: ON_PRE_SAVE ) ; $ this -> em -> persist ( $ user ) ; $ this -> em -> flush ( ) ; $ event = new UserEvent ( $ user ) ; $ this -> dispatcher -> dispatch ( $ event , UserEvent :: ON_POST_SAVE ) ; $ this -> addFlash ( 'success' , 'user.updated_profile' ) ; }
This function is called by add and edit function if given form was submitted and validated correctly.
This function is called by add and edit function if given form was submitted and validated correctly .
// Get the adjusted User Entity from the form /** @var User $user */ // Once validated, encode the password // Save the new user data into the DB