Reputation: 891
Is there any option to catch the sonata batch action inside subscriber/listener ?
Already tried to use something like sonata.admin.event.persistence.pre_batch, but it doesn't work
Why I need that ?
When user will batch delete entities which contains images (there is working custom uploader sys behind it), then I should delete all images from fileSystem also.
My current configuration
(Everything works here and I want to also add pre_batch event, but so far no success)
image.uploader.subscriber:
class: AdminBundle\EventListener\ImageUploaderSubscriber
arguments:
- '@image.remover'
- '@image.uploader'
tags:
- {name: kernel.event_listener, event: sonata.admin.event.persistence.pre_persist, method: prePersist}
- {name: kernel.event_listener, event: sonata.admin.event.persistence.pre_update, method: preUpdate}
- {name: kernel.event_listener, event: sonata.admin.event.persistence.pre_remove, method: preRemove}
Seems like hook for this event is not implemented, as it's only possible to call it from Admin Class.
So, maybe there is option to create Event by myself ?
Upvotes: 1
Views: 443
Reputation: 1528
Sonata admin model manager (used by batch delete) is actually iterating over entities. So you could hook inside doctrine lifecycle callbacks and do your logic there.
But in general preBatch
action doesn't trigger any event, but you still can override this preBatchAction
in your admin class and trigger your event from there.
Upvotes: 1