0
votes

I need to override the filter in Sonata AdminBundle to use a totally different kind of filter using images.

For now it's a html form:

/**
* @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(),
          ))
   ;
}

How can I totally override this method?

1
What do you mean by override? You need a new filter which will use the same configuration?Dmitry Malyshenko
@DmitryMalyshenko I need a totally new kind of filter. But not with form. It will be a filter with href links. Do you think it's possible?Kevin

1 Answers

0
votes

I found a way to override the template:

We override the controller to add my new logic:

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);
    }
}

The twig template:

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

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