简体   繁体   中英

sonata_type_model_list customize the admin class called

I am looking for the solution to customize the linked admin class when I use a sonata_type_model_list form type in my admin classes.

An example : I have 2 admin for one entity named EntityA: class EntityA class EntityA1Admin class EntityA2Admin

This entity is linked in many_to_one relationships with others entities : EntityB and EntityC.

In EntityBAdmin I want to call A1Admin on $formMapper->add('entityA','sonata_type_model_list');

In EntityCAdmin I want to call A2Admin on $formMapper->add('entityA','sonata_type_model_list');

Is there any solution to set manually the admin class that should be call by sonata_type_model_list ?

At least, if it's not possible, is there anyway to customize the default filters in the list view ? (is it possible to customize $dataGridValues through sonata_type_model_list field ?)

Thanks by advance (I already spend hours to find the solution in the code, but i can't find any clear solution....)

If I were you, I would go against using multiple admins for a single entity. I would first try to use some sort of context or parameters, to distinguish on what to show and what to not show in each case for the same EntityA admin (instead of using two separate admins for EntityA).

I believe you want to change filters that are shown in sonata_type_model_list . You might want to try this to know, whether you EntityA admin is being called from within sonata_type_model_list window:

protected function configureDatagridFilters(DatagridMapper $filterMapper)
{
    $request = $this->getRequest();
    if ($request->query->get('pcode') == '_entity_b_code_') {
        ...
    }
}

Then accordingly add or not add needed filter fields depending on the context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM