Your IP : 216.73.217.117


Current Path : /var/www/v3.cesa.co.za/vendor/sonata-project/admin-bundle/src/Action/
Upload File :
Current File : /var/www/v3.cesa.co.za/vendor/sonata-project/admin-bundle/src/Action/SearchAction.php

<?php

declare(strict_types=1);

/*
 * This file is part of the Sonata Project package.
 *
 * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Action;

use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\BCLayer\BCHelper;
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

final class SearchAction
{
    public function __construct(
        private Pool $pool,
        private TemplateRegistryInterface $templateRegistry,
        private Environment $twig,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        return new Response($this->twig->render($this->templateRegistry->getTemplate('search'), [
            'base_template' => $request->isXmlHttpRequest() ?
                $this->templateRegistry->getTemplate('ajax') :
                $this->templateRegistry->getTemplate('layout'),
            'query' => BCHelper::getFromRequest($request, 'q', ''),
            'groups' => $this->pool->getDashboardGroups(),
        ]));
    }
}