Is there a smarter way to disable Doctrine2 filters in Symfony2.1?

I use Gedmo Doctrine Extensions , for example SoftDeletable, and at different points I need to disable this filter so that users can interact with soft remote objects or soft remote relations of an entity.

This includes, but is not limited to, once in the controller and again in a specific area of ​​SonataAdmin.

So far, the solution I have found is to call getFilters () on em and disable softdeleteable, which is good.

However, both sonata classes and controllers seem to go through multiple executions, which leads to a fatal attempt 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'); } 

It seems to be at least hacked.

But there are also other problems, such as determining the scope of a team. I have not noticed any problems with the interface yet, but in the administrator there are several executions, one of which is to create navigation (I think), means that the filter is always disabled, and only the ability to do it directly on em seems to me that this will cause hellish load of problems as soon as I don't want the feature to be disabled somewhere in the backend.

Is there a better way to do this?

+7
source share
1 answer

While at the time of writing the answer the answer was negative, now the functionality for disabling filters based on each object has been added like this:

 // 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

+3
source

All Articles