How to process each entity in SonataAdminBundle list view?

假如想象 提交于 2020-01-13 19:57:07

问题


How to apply some code to each entity being displayed in Admin's list view?

For example, if I have a TagManager and need to load tags for each entity being displayed, how do I do that? Is there a method to override in entity's Admin or can I bind to some list form event? I could not find a place to do that.

I don't wan't to bind to entity's onLoad event.


回答1:


EDIT: In your entityAdminController :

public function listAction()
{
    if (false === $this->admin->isGranted('LIST')) {
        throw new AccessDeniedException();
    }

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

    foreach($datagrid->getResults() as $object)
    {
        //do what you want with $object
    }

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

    return $this->render($this->admin->getTemplate('list'), array(
        'action'   => 'list',
        'form'     => $formView,
        'datagrid' => $datagrid
    ));
}


来源:https://stackoverflow.com/questions/18653033/how-to-process-each-entity-in-sonataadminbundle-list-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!