Created
April 16, 2015 09:37
-
-
Save whitewhidow/2300a2c82dac61a455d5 to your computer and use it in GitHub Desktop.
SonataAdminBundle : datagrid filter to filter by role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
->add('with_role', 'doctrine_orm_callback', array('label' => 'role', | |
'callback' => function($queryBuilder, $alias, $field, $value) { | |
if (!$value['value']) { | |
return; | |
} | |
$queryBuilder->andWhere($alias.'.roles LIKE :role'); | |
$queryBuilder->setParameter('role', '%'.$value['value'].'%'); | |
return true; | |
}, | |
'field_type' => 'choice', | |
'field_options' => array('choices' => array("ROLE_SUPER_ADMIN" => "ROLE_SUPER_ADMIN", "ROLE_EDITION_ADMIN" => "ROLE_EDITION_ADMIN", "ROLE_USER" => "ROLE_USER")) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment