forms - How to get NULL as an option in a datagrid relation in sonata admin bundle? -


i added following sonata admin in order filter category. however, list not show null option category. want want able filter category when category null instead of entity.

how can 1 achieve this? current configuration:

protected function configuredatagridfilters(datagridmapper $datagridmapper) {     $datagridmapper         ->add("category"); } 

try this:

protected function configuredatagridfilters(datagridmapper $datagridmapper) {     $datagridmapper->add("category", 'doctrine_orm_callback', array(         'callback' => function ($querybuilder, $alias, $field, $value) {                 /**                  * @var querybuilder $querybuilder                  */                 if ($value['value']) {                     if ($value['value'] == 0) {                         $querybuilder->andwhere($querybuilder->expr()->isnull($alias.'.category'));                         return true;                     } else {                        $category = $this->getconfigurationpool()->getcontainer()->get('doctrine.orm.entity_manager')->getreference('acmebundle:category', $value['value']);                        $querybuilder->andwhere($querybuilder->expr()->eq($alias.'.category', $category));                         return true;                     }                 }             },         'field_type' => 'choice',         'field_options' => array(             'choices' => $this->getcategorychoices()                 ),         'label' => 'category'     )); }  private function getcategorychoices() {     $categories = $this->getconfigurationpool()->getcontainer()->get('doctrine.orm.entity_manager')->getrepository('acmebundle:category')->findall();      $choices["0"] = "null";     foreach($categories $category) {          $choices["{$category->getid()}"] = $category->getname();     }      return $choices; } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -