Ojs\JournalBundle\Controller\JournalUserController::createUserAction PHP Метод

createUserAction() публичный Метод

Creates a new User entity.
public createUserAction ( Request $request ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
Результат Symfony\Component\HttpFoundation\RedirectResponse | Symfony\Component\HttpFoundation\Response
    public function createUserAction(Request $request)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        $eventDispatcher = $this->get('event_dispatcher');
        if (!$this->isGranted('CREATE', $journal, 'userRole')) {
            throw new AccessDeniedException("You are not authorized for this page!");
        }
        $entity = new User();
        $form = $this->createCreateForm($entity, $journal->getId());
        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $factory = $this->get('security.encoder_factory');
            $encoder = $factory->getEncoder($entity);
            $password = $encoder->encodePassword($entity->getPassword(), $entity->getSalt());
            $entity->setPassword($password);
            $entity->setEnabled(true);
            $em->persist($entity);
            $journalUser = new JournalUser();
            $journalUser->setUser($entity);
            $journalUser->setJournal($journal);
            $event = new JournalItemEvent($journalUser);
            $eventDispatcher->dispatch(JournalUserEvents::PRE_CREATE, $event);
            $em->persist($event->getItem());
            $em->flush();
            $event = new JournalItemEvent($event->getItem());
            $eventDispatcher->dispatch(JournalUserEvents::POST_CREATE, $event);
            if ($event->getResponse()) {
                return $event->getResponse();
            }
            $this->successFlashBag('successful.create');
            return $this->redirectToRoute('ojs_journal_user_edit', ['journalId' => $journal->getId(), 'id' => $journalUser->getId()]);
        }
        return $this->render('OjsJournalBundle:JournalUser:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
    }