我想在奏鸣曲字段列表configureListFields()
这可能在configureDatagridFilters()方法中如下所示:
protected function configureDatagridFilters(DatagridMapper $filter)
{
$filter
->add('user', 'doctrine_orm_callback', array(
'callback' => array($this, 'customMethod'),
));
}
但是在configureListFields()方法中可以吗?
答案 0 :(得分:0)
您使用 doctrine_orm_callback 的尝试是正确的: Doctrine2 ORM Admin's documentation - Reference - Filter Field Definition (2.2) - 5.5.3. Callback
使用提供的示例并将评论替换为预订,然后将您的条件应用于构建器:
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('title')
->add('enabled')
->add('tags', null, array(), null, array('expanded' => true, 'multiple' => true))
->add('author')
->add('with_open_comments', 'doctrine_orm_callback', array(
'callback' => function($queryBuilder, $alias, $field, $value) {
if (!$value) {
return;
}
$queryBuilder->leftJoin(sprintf('%s.comments', $alias), 'c');
$queryBuilder->andWhere('c.status = :status');
$queryBuilder->setParameter('status', Comment::STATUS_MODERATE);
return true;
},
'field_type' => 'checkbox'
))
;
}