2

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.

4

1 回答 1

6

编辑:在您的 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
    ));
}
于 2013-09-06T08:45:09.257 回答