-
-
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
Fix getSubject method when admin has parentFieldDescription #4581
Fix getSubject method when admin has parentFieldDescription #4581
Conversation
bad42ce
to
ecd2139
Compare
ecd2139
to
46de791
Compare
46de791
to
06f04b7
Compare
PR rebased, tests are now ok ! |
Does this fix #4556? |
@jlamur No sorry, that's not related ! |
Nevermind I confused |
Thanks @EmmanuelVella ! |
This change has broken my app because is firing extra (and unnecessary) calls to configureFormFields method after click on update button in edit form view. I've put a breakpoint inside a configureFormFields method, in v3.20.1 and when I click on update button, my debugger never stops there. After this change of code, the debugger stops there with the same use case. This behaviour brokes my app becuase it's executing a "strange mess". I my code, I'm using this kind of relations: $formMapper
->add(
'auditWindmillBlades',
CollectionType::class,
array(
'label' => ' ',
'required' => false,
'btn_add' => false,
'cascade_validation' => true,
'error_bubbling' => true,
'type_options' => array(
'delete' => false,
),
),
array(
'edit' => 'inline',
'inline' => 'table',
)
) Should I open a new issue? |
Probably. @EmmanuelVella can you help? |
Hello @davidromani, I tried with a (native) collection type, submitted the form with success. Could you please elaborate (more details about what happens) and tell me how to reproduce this behavior ? |
@EmmanuelVella yes, I've a public repository of my app (with fixtures, easy to install and deploy) if you want to try it, or I can describe my entity relations and my Admin form mapper. Plus I have some Sonata hooks defined (pre-persist, per-update). What do you prefer? Another question what "native collection type" means? My app still broken If I use "sonata_type_collection" insetad of CollectionType::class declarations if you are thinking about it. |
@davidromani I tried both collection types ( |
Hmmmmm |
@EmmanuelVella the problem is focused with parent and child admins and how this affect to the getSubject() method call behaviour. Please check if $this->hasParentFieldDescription() call can cause instance “construction” problems or fire some unexpected behaviour. SonataAdminBundle/Admin/AbstractAdmin.php Line 1689 in f7534c2
|
@greg0ire I meant ( |
@EmmanuelVella you can try with my real app cloning this repo https://github.com/Flexible-User-Experience/fibervent & checkout to this commit https://github.com/Flexible-User-Experience/fibervent/commit/115d0336359fc5bf54cc3aa56a96bec04aad6096 Before to downgrade Sonata up to v3.20.1 it fails. Next commit (https://github.com/Flexible-User-Experience/fibervent/commit/f8f33b0c1640087c8f1d90f393bda58a2e625cc9) it works well. |
@davidromani Yes I get that. I did this PR to fix an issue where the subject was incorrect in case of embedded forms (the ID in the url was used to load the children). I tried to execute your project but there are too many requirements, it would be too long to install for me. Could you paste me the stack trace please ? |
BTW I highly suspect this behavior : #2076 You seem to use a sonata collection, with an admin which itself contains another embedded admin. In this case, I don't see any solution, as the subject is set in the embedded admin once the form data is set, so you can't use getSubject() before this happens. To summarize :
Hope that's clear... |
On composer install it's quite easy to apply all of default parameters.yml.dist values (according to your DB). And then execute $php app/console hautelook_alice:doctrine:fixtures:load --env=dev command. Finally you can go to the app_dev.php/admin/audits/audit/1/edit path and try to change Audit status and click on update button. |
Ok, that's what I thought. You have an SonataAdminBundle/Form/Type/AdminType.php Line 58 in f7534c2
However, your Before my PR, the subject of your I think it's not a good idea to call getSubject in the You should event listeners instead : https://symfony.com/doc/current/form/events.html#event-listeners |
Changelog
To do
Subject
When an admin has a
parentFieldDescription
, theAbstractAdmin::getSubject
method should not use the url id parameter to load the object (because the id correspond to the root object only).Example: I have an issue when submitting a form with a collection which contains an
AdminType
field. InAdminType
, this line loads a (random) collection element by using the url id (which is the root object id) : https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Form/Type/AdminType.php#L57Should fix #2879