简体   繁体   中英

Render Sonata admin list in block

I try to create a block for the main page based on list action sonata admin is possible?

example 
  dashboard:
        blocks:
            - { type: mea.task.block, position: center, roles: [ ROLE_WORKER ] }

Here is block render

class TaskListAdminBlock extends AbstractAdminBlockService
{
    /**
     * {@inheritdoc}
     */
    public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $controller = 'Mea\TaskBundle\Sonata\Controller\TaskCrudController::listAction';
        $path       = [
            '_controller' => $controller,
        ];

        $subRequest = $this->requestStack->getMasterRequest()->duplicate($query, null, $path);

        return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
    }
}

TaskCrudController is sonata admin controller for task

this throw error

There is no `_sonata_admin` defined for the controller `Mea\TaskBundle\Sonata\Controller\TaskCrudController` and the current route ``

Is possible to fix this code or archive this in another way?

Ok I found beautifully solution This renders in ajax made admin list

public function execute(BlockContextInterface $blockContext, Response $response = null)
    {

        $controller = 'Mea\TaskBundle\Sonata\Controller\TaskCrudController::listAction';
        $path = array(
            '_controller' => $controller
        );

        $query = [
            'filter'=>[
                '_per_page'=>4,
            ],
        ];

        $subRequest = $this->requestStack->getMasterRequest()->duplicate($query, null, $path);
        $subRequest->headers->set('X-Requested-With','XMLHttpRequest');
        $subRequest->request->set('_sonata_admin','mea.task.task.admin');

        $response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);

        return $response;

    }

Not fully work fine - ajax mode switch actions to select.

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