Since the part where the error was included was not answered here, and I had to delve into the FOSUserBundle code, let me also add to this post how to add error messages to the loginPartial.html.twig form:
See the file / vendor / friendsofsymfony / user-bundle / Controller / SecurityController.php
This controller has a loginAction that creates an error. All you have to do in the controller that you use to render loginPartial is to add the following code to this controller.
$session = $request->getSession(); // get the error if any (works with forward and redirect -- see below) if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { $error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR); } elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR); } else { $error = null; } return $this->render('YourDemoBundle:Default:index.html.twig', ['error' => $error]);
In this case, you simply use the same code in your controller to generate any login error messages, i.e. wrong password, etc.
Now in the branch that shows the form, simply add the following: {% include 'YourDemoBundle: Security: loginPartial.html.twig'%}
And in the loginPartial.html.twig file, enter the following:
{% block fos_user_content %} {% if error %} <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div> {% endif %}`Let the rest of the form be as is....and then endblock ofcourse..{% endblock fos_user_content %}`
It should do it
Tragaknight
source share