The callback in sonata_type_model_autocomplete configuration is a callable function that can be used to modify the query which is used to retrieve autocomplete items.
The callback should receive three parameters – the Admin instance, the property (or properties) defined as searchable and the search value entered by the user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$formMapper->add('category', 'sonata_type_model_autocomplete', array( 'property' => 'name', 'multiple' => false, 'required' => false, 'callback' => function ($admin, $property, $value) { $datagrid = $admin->getDatagrid(); $queryBuilder = $datagrid->getQuery(); $queryBuilder ->andWhere($queryBuilder->getRootAlias() . '.position=:posValue') ->andWhere($queryBuilder->getRootAlias() . '.context=:contextValue') ->setParameter('posValue', 0) ->setParameter('contextValue', 'store') ; $datagrid->setValue($property, null, $value); }, )) |
No comments yet.