EasyAdminBundle: QueryBuilder in TypeOptions fails
Hey all,
Currently I’m using version 1.16.2 and the functionality described in #1145 fails with Expected argument of type "Doctrine\ORM\QueryBuilder or \Closure", "string" given.
The config looks like the following:
CampaignType:
class: Bundle\Entity\CampaignType
controller: Bundle\Controller\EasyAdmin\SomeController
edit:
fields:
- { property: 'purposes', type_options: { query_builder: "Bundle\Repository\EasyAdmin\SomeRepo::getAccessible" } }
with the method getAccessible specified in the repository
public static function getAccessible(EntityRepository $er) {
return ...
}
Anyone got an idea, why this fails?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 18 (1 by maintainers)
i can confirm that this works under EasyAdmin 1.17, Sf 3.3.13:
- { property: 'types', type_options: { 'expanded':false, 'multiple': true, 'query_builder': 'YourBundle\Repository\YourRepository::pubStaticFunction', 'group_by': 'category'} }group_byis obviously optional but i needed it in my case.however, it was hard to find for me the right syntax for the repository function, as it’s not the same as described in Symfony doc, so i paste an example here, in case it can help :
let’s say this is about Product and Categories :
or a simple orderBy:
@srosset81
Try to add this:
I don’t know why. It works for me. In my case, as I re-add this field at form builder level, I only declare it without any options at config level. Full code (
css_classis used for javascript needs):admin.yml
Custom AdminController
In my case, I use what is proposed by Javier in #1145. I use a custom admin controller and I introduce the query_builder in options at form builder level.
Example with my Event entity:
EasyAdmin4 solution Note: The keyword (alias)
entityis important@javiereguiluz probably the docs needs to be updated as passing a callable string syntax is feasible for
query_builderoption (see source):This is working for me now (EA=1.17, SF=3.3.10):