-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Submitting a form with ->render instead of ->renderWithExtraParams does not work #8120
Comments
cc @core23 |
I can reproduce the issue, but I have no idea why this happens, as both methods do exactly the same stuff and do not provide some unique id https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/EventListener/AdminEventListener.php#L40-L59 |
In the listener there is
Maybe you're in the catch (?) |
No, I tested, the addVariable below this code is called. |
I found what causes the problem. If the code setting twig globals is moved inside or after CRUDController::configureAdmin(), and uses CRUDController::admin property instead of a new instance of the admin, it works. |
Do you want to try the PR @AntoineRoue ? (or @core23 ?) |
Should we set these twig globals in CRUDController::configureAdmin() ? |
It seems fine to me if it does the job. (Is it to you @core23 ?) Do you know if
will allows to override the twig global ? (which would be great to allow the user to easily override our default value) |
Yes, your example would override the twig global. |
Environment
Sonata packages
show
Symfony packages
show
PHP version
Subject
The pull request #8116 auto-injects admin in twig so that CRUDController::renderWithExtraParams can be replaced by ::render instead. However, in a form edition or creation, the injected admin uniqId parameter and other parameters linked to the form are null. Thus, when we submit the form without uniqid, the form is not recognized as submitted.
Steps to reproduce
Create a basic admin form, replace renderWithExtraParams by render in CRUDController::editAction and CRUDController::createAction, then try to create or edit an object.
Expected results
Submitting the form once works.
Actual results
Submitting the form once does not work, we have to submit it another time. In fact, one submit out of two does not work because when we are redirected to a form, the uniqId parameter is null.
Result of
{{ dump(admin) }}
in the form template, with render : https://i.imgur.com/ZbeVvcv.pngResult of
{{ dump(admin) }}
in the form template, with renderWithExtraParams : https://i.imgur.com/aNXxHXG.pngThe text was updated successfully, but these errors were encountered: