src/Eccube/Controller/TopController.php line 53

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Eccube\Form\Type\SearchProductBlockType;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Eccube\Repository\ProductRepository;
  21. use Eccube\Repository\CategoryRepository;
  22. class TopController extends AbstractController
  23. {
  24.     /**
  25.      * @var RequestStack
  26.      */
  27.     protected $requestStack;
  28.     /**
  29.      * @var CategoryRepository
  30.      */
  31.     protected $categoryRepository;
  32.     /**
  33.      * TopController constructor.
  34.      *
  35.      * @param CategoryRepository $categoryRepository
  36.      */
  37.     public function __construct(RequestStack $requestStackCategoryRepository $categoryRepository) {
  38.         $this->requestStack $requestStack;
  39.         $this->categoryRepository $categoryRepository;
  40.     }
  41.     /**
  42.      * @Route("/", name="homepage", methods={"GET"})
  43.      * @Template("index.twig")
  44.      */
  45.     public function index(Request $requestProductRepository $productRepository)
  46.     {
  47.         $builder $this->formFactory
  48.             ->createNamedBuilder(''SearchProductBlockType::class)
  49.             ->setMethod('GET');
  50.         $event = new EventArgs(
  51.             [
  52.                 'builder' => $builder,
  53.             ],
  54.             $request
  55.         );
  56.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_BLOCK_SEARCH_PRODUCT_INDEX_INITIALIZE);
  57.         $request $this->requestStack->getMainRequest();
  58.         $form $builder->getForm();
  59.         $form->handleRequest($request);
  60.         $Categories $this->categoryRepository->getList();
  61.         $products $productRepository->findFirstNineProducts();
  62.         return [
  63.             'form' => $form->createView(),
  64.             'products' => $products,
  65.             'Categories' => $Categories,
  66.         ];
  67.     }
  68. }