Symfony2 - 覆盖Sonata AdminBundle过滤器

时间:2016-08-24 09:07:21

标签: symfony sonata-admin

我需要覆盖Sonata AdminBundle中的过滤器,以使用完全不同类型的过滤器使用图像。

现在它是一个HTML格式:

/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
   $datagridMapper
       ->add('orderIdentifier', null, ['label' => 'N°'])
       ->add('orderDeliveryAddress', null, ['label' => 'Client'])
       ->add('partner.name', null, ['label' => 'Partenaire'])
       ->add('postal', null, ['label' => 'Code postal'])
       ->add('product.code', null, ['label' => 'Produit'])
       ->add('volume', null, ['label' => 'Volume', 'template'])
       ->add('deliveryType', null, ['label' => 'Type de livraison'])
       ->add('createdAt', null, ['label' => 'Date'])
       ->add('state', null, array('show_filter' => true), 'choice', array(
              'choices' => $this->getConfigurationPool()->getContainer()->get('fm.command.order_status_manager')->countAllOrderByStatus(),
          ))
   ;
}

如何完全覆盖此方法?

1 个答案:

答案 0 :(得分:0)

我找到了覆盖模板的方法:

我们覆盖控制器以添加我的新逻辑:

namespace Site\AdminBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;

class CommandManagementController extends Controller
{
    public function listAction()
    {
        $request = $this->getRequest();

        $this->admin->checkAccess('list');

        $preResponse = $this->preList($request);
        if ($preResponse !== null) {
            return $preResponse;
        }

        if ($listMode = $request->get('_list_mode')) {
            $this->admin->setListMode($listMode);
        }

        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        // set the theme for the current Admin Form
        $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());

        return $this->render('Admin/Command/list.html.twig', array(
            'action' => 'list',
            'form' => $formView,
            'datagrid' => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
        ), null, $request);
    }
}

树枝模板:

{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}

{% block list_filters %}
        {# Your HTML here #}
{% endblock %}