SonataDoctrineORM - Model Extends

I am using Sonata with SonataAdmin and SonataOrm as stated in several tutorials.

I just would like to remove some default DoctrineOrmBundle- ModelManager.php method

I tried to override ModelManager by putting

<?php

namespace Project\AdminBundle\Model;

use Sonata\DoctrineORMAdminBundle\Model\ModelManager as ModelManager;

class ModelManager extends ModelManager
{

/**
 * {@inheritdoc}
 */
public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid)
{
    $values = $datagrid->getValues();
    $values = $_GET['filter'];
    if ($fieldDescription->getName() == $values['_sort_by']) {
        //echo $fieldDescription->getName() . ' --- ' . $values['_sort_order'] . '<br />';
        if ($values['_sort_order'] == 'ASC') {
            $values['_sort_order'] = 'DESC';
        } else {
            $values['_sort_order'] = 'ASC';
        }
    } else {
        $values['_sort_order'] = 'ASC';
        $values['_sort_by']    = $fieldDescription->getName();
    }

    return array('filter' => $values);
  }

}
?>

      

And tell Sonata DoctrineOrm to use it as default.

But I don't know how to do it.

Am I at least on the right track?

+1


source to share


1 answer


You still need to tell the admin that you are using your own ModelManager. To do this, you need to use the setModelManager method when defining your admin services. Services.yml:

services:
    #new model manager
    myproject.model_manager:
         class: Project\AdminBundle\Model\ModelManager
         arguments:
             - '@doctrine'

    #define admin service
    myproject_admin.project:
        class: MyProject\MyBundle\Admin\ProjectAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: Projects, label: Projects }
        arguments:
            - null
            - MyProject\MyBundle\Entity\Project
            - SonataAdminBundle:CRUD
        calls:
            - [setModelManager, ['@myproject.model_manager'] ]

      



More details in the next section of the documentation: http://sonata-project.org/bundles/admin/2-2/doc/reference/advanced.html

+3


source







All Articles