I'm using Gedmo Doctrine Extensions, such as SoftDeletable, and at various points I need to disable this filter so that users can interact with soft deleted entities, or soft deleted relations of an entity.
This includes but is not limited to, once in a controller and again in a specific area of the SonataAdmin.
So far the solution I've found is to call getFilters() on the em and disable softdeleteable, which is fine.
However both sonata admin classes and controllers seem to go through multiple executions, which causes a fatal attempting to disable an already disabled filter, so I have to do this:
if (array_key_exists('softdeleteable', $this->em->getFilters()->getEnabledFilters())) {
$this->em->getFilters()->disable('softdeleteable');
}
Which seems itself hacky to say the least.
But also, there are other problems, such as scoping of the command. I haven't spotted any problems frontend yet, but in the admin, the multiple executions, one of which is to build the navigation (I think) means that the filter is always disabled, and only being able to do this directly on the em seems to me like it will cause a hell of a load of issues as soon as I don't want the functionality disabled somewhere backend.
Is there a better way of doing this?
Whilst at the time of writing, the answer was no, the functionality to disable filters on a per-entity basis has now been added, like so:
// Enable / Disable filter filter, for specified entity (default is enabled for all)
$filter = $em->getFilters()->enable('soft-deleteable');
$filter->disableForEntity('Entity\Article');
$filter->enableForEntity('Entity\Article');
Documentation: https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With