Loading wrong template
Hi I found a problem,
Every register route loads wrong (default) tempate. I found that is caused by those lines in
RegistrationManager.php
$result = $this->controller->registerAction($this->container->get('request'));
if ($result instanceof RedirectResponse) {
return $result;
}
$this->controller->registerAction($this->container->get('request'));
This renders default register form and prevents to run this:
$template = $this->userDiscriminator->getTemplate('registration');
if (is_null($template)) {
$engine = $this->container->getParameter('fos_user.template.engine');
$template = 'FOSUserBundle:Registration:register.html.'.$engine;
}
$form = $this->formFactory->createForm();
return $this->container->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
));
That's because this in RegistrationController in FOSUserBundle if (null !== $event->getResponse()) { return $event->getResponse(); }
doesn't return null
When I delete wrong lines from RegistrationManager.php - everything works well.
Am I doing something wrong, or there is a bug?
Here is my config.yml
config.yml
pugx_multi_user:
users:
chiro:
entity:
class: Bos\UserBundle\Entity\Chiro
registration:
form:
type: Bos\UserBundle\Form\RegistrationFormType
name: bos_user_registration
validation_groups: [Registration, Default]
template: BosUserBundle:Registration:register.html.twig
patient:
entity:
class: Bos\UserBundle\Entity\Patient
registration:
template: BosUserBundle:Registration:register_patient.html.twig
form:
type: Bos\UserBundle\Form\RegistrationPatientFormType
name: bos_user_registration_patient
Same problem here, except when I remove the lines from RegistrationManager.php as you suggested, the form is not performed after submit. Instead it shows the empty registration form again.
Any ideas how to fix this?
Well, found a solution by myself => need to check the request object for POST method, like so:
RegistrationManager.php (starting line 65)
$request = $this->container->get('request');
if ($request->getMethod() == 'POST') {
$result = $this->controller->registerAction($request);
if ($result instanceof RedirectResponse) {
return $result;
}
}
Maybe some official could check this issue (wether this is really a bug or OP and I are doing something wrong) and commit the suggested change?
@greg-man could you open a PR with the fix and a test to cover it?
Too bad, as I dug further I found that the fix won't cover the problem fully. It still exists, when a form is submitted, but rejected for some constraints, e.g. duplicate email. Any ideas?
Weird, don't know why, but custom templates are working now as expected. Must have done something wrong, doesn't seem to be a bug at all.