What are the Slack Archives?
Itβs a history of our time together in the Slack Community! Thereβs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonβt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hey! I am looking for a possibility to set a custom translated "invalid csrf token" message for all
Hey! I am looking for a possibility to set a custom translated "invalid csrf token" message for all the forms used in our shop.
Since it is symfony/form as underlying package it is possible to set this in general in the corresponding configureOptions
method as
$resolver->setDefaults([ 'csrf_message' => 'some message', ]);
but this way i have to set this for each and every form. Is there a way to set this on a more abstract level?
Comments
-
did you try the glossary key
form.csrf.error.text
indata/import/common/common/glossary.csv
(for me line 3564)?0 -
Uff may be i thought too complicated, will try this! Thx!
0 -
Hey Marco! Unfortunally thats not so easy. the message form.csrf.error.text is only used in some single places but not as a general translation for the symfony message.
0 -
Also it is not only used in case of the token was invalid or absent (as it is designed to be in symfony by setting it in the
$resolver->setDefaults(...)
method) but in every case of!$form->isValid()
what can have other reasons. I tested this in current spryker-b2b-demo shop.0 -
Ok i found a solution. For people who are interested in:
β’ create a newPyz\Yves\Form\Plugin\Provider\CsrfExtensionServiceProvider
and register it in YvesBootstrap
β’ set$app['form.extension.csrf']
with own CsrfExtension-Class from project level in CsrfExtensionServiceProvider:$app['form.extension.csrf'] = $app->share(function ($app) { if (isset($app['translator'])) { return new CsrfExtension($app['form.csrf_provider'], $app['translator']); } return new CsrfExtension($app['form.csrf_provider']); });
β’ in
CsrfExtension
load ownFormTypeCsrfExtension
from project level
β’ inFormTypeCsrfExtension
setcsrf_message
to your needs inconfigureOptions
method. This also can be a translation key of your glossary
Not a very beautiful way of resolving this problem, but the best i found.0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random