Skip to content

Commit a711a6d

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Add `getter` and `setter` in the section on basic form options use a consistent route name for the login form
2 parents 1b7ae02 + faad689 commit a711a6d

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

reference/forms/types/form.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ The actual default value of this option depends on other field options:
7676

7777
.. include:: /reference/forms/types/options/form_attr.rst.inc
7878

79+
``getter``
80+
~~~~~~~~~~
81+
82+
**type**: ``callable`` **default**: ``null``
83+
84+
When provided, this callable will be invoked to read the value from
85+
the underlying object that will be used to populate the form field.
86+
87+
More details are available in the section on :doc:`/form/data_mappers`.
88+
89+
.. versionadded:: 5.2
90+
91+
Form mapping callbacks were added in Symfony 5.2.
92+
7993
.. include:: /reference/forms/types/options/help.rst.inc
8094

8195
.. include:: /reference/forms/types/options/help_attr.rst.inc
@@ -112,6 +126,20 @@ The actual default value of this option depends on other field options:
112126

113127
.. include:: /reference/forms/types/options/required.rst.inc
114128

129+
``setter``
130+
~~~~~~~~~~
131+
132+
**type**: ``callable`` **default**: ``null``
133+
134+
When provided, this callable will be invoked to map the form value
135+
back to the underlying object.
136+
137+
More details are available in the section on :doc:`/form/data_mappers`.
138+
139+
.. versionadded:: 5.2
140+
141+
Form mapping callbacks were added in Symfony 5.2.
142+
115143
.. include:: /reference/forms/types/options/trim.rst.inc
116144

117145
.. include:: /reference/forms/types/options/validation_groups.rst.inc

security.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ First, create a controller for the login form:
655655
656656
class LoginController extends AbstractController
657657
{
658-
#[Route('/login', name: 'login')]
658+
#[Route('/login', name: 'app_login')]
659659
public function index(): Response
660660
{
661661
return $this->render('login/index.html.twig', [
@@ -678,9 +678,9 @@ Then, enable the form login authenticator using the ``form_login`` setting:
678678
main:
679679
# ...
680680
form_login:
681-
# "login" is the name of the route created previously
682-
login_path: login
683-
check_path: login
681+
# "app_login" is the name of the route created previously
682+
login_path: app_login
683+
check_path: app_login
684684
685685
.. code-block:: xml
686686
@@ -697,8 +697,8 @@ Then, enable the form login authenticator using the ``form_login`` setting:
697697
<config>
698698
<!-- ... -->
699699
<firewall name="main">
700-
<!-- "login" is the name of the route created previously -->
701-
<form-login login-path="login" check-path="login"/>
700+
<!-- "app_login" is the name of the route created previously -->
701+
<form-login login-path="app_login" check-path="app_login"/>
702702
</firewall>
703703
</config>
704704
</srv:container>
@@ -713,10 +713,10 @@ Then, enable the form login authenticator using the ``form_login`` setting:
713713
714714
$mainFirewall = $security->firewall('main');
715715
716-
// "login" is the name of the route created previously
716+
// "app_login" is the name of the route created previously
717717
$mainFirewall->formLogin()
718-
->loginPath('login')
719-
->checkPath('login')
718+
->loginPath('app_login')
719+
->checkPath('app_login')
720720
;
721721
};
722722
@@ -739,7 +739,7 @@ Edit the login controller to render the login form:
739739
740740
class LoginController extends AbstractController
741741
{
742-
#[Route('/login', name: 'login')]
742+
#[Route('/login', name: 'app_login')]
743743
- public function index(): Response
744744
+ public function index(AuthenticationUtils $authenticationUtils): Response
745745
{
@@ -777,7 +777,7 @@ Finally, create or update the template:
777777
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
778778
{% endif %}
779779

780-
<form action="{{ path('login') }}" method="post">
780+
<form action="{{ path('app_login') }}" method="post">
781781
<label for="username">Email:</label>
782782
<input type="text" id="username" name="_username" value="{{ last_username }}"/>
783783

@@ -801,7 +801,7 @@ Finally, create or update the template:
801801

802802
The form can look like anything, but it usually follows some conventions:
803803

804-
* The ``<form>`` element sends a ``POST`` request to the ``login`` route, since
804+
* The ``<form>`` element sends a ``POST`` request to the ``app_login`` route, since
805805
that's what you configured as the ``check_path`` under the ``form_login`` key in
806806
``security.yaml``;
807807
* The username (or whatever your user's "identifier" is, like an email) field has
@@ -914,7 +914,7 @@ be ``authenticate``:
914914
{# templates/login/index.html.twig #}
915915

916916
{# ... #}
917-
<form action="{{ path('login') }}" method="post">
917+
<form action="{{ path('app_login') }}" method="post">
918918
{# ... the login fields #}
919919

920920
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">

0 commit comments

Comments
 (0)