2016-08-24 52 views
0

我需要重寫Sonata AdminBundle中的過濾器,以使用完全不同的使用圖像的過濾器。Symfony2 - Override Sonata AdminBundle filter

現在它是一個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(), 
     )) 
    ; 
} 

我怎麼能完全覆蓋此方法?

+0

你通過覆蓋的意思?你需要一個新的過濾器,它將使用相同的配置? –

+0

@DmitryMalyshenko我需要一種全新的過濾器。但不與形式。它將是一個帶有「href」鏈接的過濾器。你認爲這有可能嗎? – Kevin

回答

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 %}