-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add block prefix to csrf token field #29862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5a7c246
to
0f369c9
Compare
@@ -90,9 +90,10 @@ public function finishView(FormView $view, FormInterface $form, array $options) | |||
$tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: \get_class($form->getConfig()->getType()->getInnerType())); | |||
$data = (string) $options['csrf_token_manager']->getToken($tokenId); | |||
|
|||
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, array( | |||
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, [ | |||
'block_prefix' => 'token', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
token
-> csrf_token
?
This looks nice to me ... but I'd like to ask @HeahDude and @vudaltsov if they can imagine any problem for adding this option unconditionally and for "hardcoding" its value. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really simple and nice addition, thank you very much!
Thank you @alexander-schranz. |
This PR was squashed before being merged into the 4.3-dev branch (closes #29862). Discussion ---------- Add block prefix to csrf token field | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... | License | MIT | Doc PR | symfony/symfony-docs#10867 Currently I use the following code snippet to overwrite the token rendering: ```twig {%- block hidden_widget -%} {%- if form.vars.name == '_token' -%} {{ block('app__token_widget') }} {%- else -%} {{ block('hidden_widget', 'form_div_layout.html.twig') }} {%- endif -%} {%- endblock hidden_widget -%} {%- block app__token_widget %} {{ render_esi(controller('SuluFormBundle:FormWebsite:token', { 'form': form.parent.vars.name })) }} {%- endblock app__token_widget -%} ``` With the change of https://symfony.com/blog/new-in-symfony-4-3-simpler-form-theming this workaround can now be removed and the following can be used: ```twig {%- block token_widget %} {{ render_esi(controller('SuluFormBundle:FormWebsite:token', { 'form': form.parent.vars.name })) }} {%- endblock token_widget -%} ``` Commits ------- 02bd689 Add block prefix to csrf token field
Currently I use the following code snippet to overwrite the token rendering:
With the change of https://symfony.com/blog/new-in-symfony-4-3-simpler-form-theming this workaround can now be removed and the following can be used: