Skip to content

Instantly share code, notes, and snippets.

@whitewhidow
Created April 16, 2015 09:37
Show Gist options
  • Save whitewhidow/2300a2c82dac61a455d5 to your computer and use it in GitHub Desktop.
Save whitewhidow/2300a2c82dac61a455d5 to your computer and use it in GitHub Desktop.
SonataAdminBundle : datagrid filter to filter by role
->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