vendor/shopware/storefront/Controller/NavigationController.php line 39

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Controller;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedHook;
  6. use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
  7. use Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoadedHook;
  8. use Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoaderInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * @internal
  14.  * Do not use direct or indirect repository calls in a controller. Always use a store-api route to get or put data
  15.  */
  16. #[Route(defaults: ['_routeScope' => ['storefront']])]
  17. #[Package('content')]
  18. class NavigationController extends StorefrontController
  19. {
  20.     /**
  21.      * @internal
  22.      */
  23.     public function __construct(
  24.         private readonly NavigationPageLoaderInterface $navigationPageLoader,
  25.         private readonly MenuOffcanvasPageletLoaderInterface $offcanvasLoader
  26.     ) {
  27.     }
  28.     #[Route(path'/'name'frontend.home.page'options: ['seo' => true], defaults: ['_httpCache' => true], methods: ['GET'])]
  29.     public function home(Request $requestSalesChannelContext $context): ?Response
  30.     {
  31.         $page $this->navigationPageLoader->load($request$context);
  32.         $this->hook(new NavigationPageLoadedHook($page$context));
  33.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  34.     }
  35.     #[Route(path'/navigation/{navigationId}'name'frontend.navigation.page'options: ['seo' => true], defaults: ['_httpCache' => true], methods: ['GET'])]
  36.     public function index(SalesChannelContext $contextRequest $request): Response
  37.     {
  38.         $page $this->navigationPageLoader->load($request$context);
  39.         $this->hook(new NavigationPageLoadedHook($page$context));
  40.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  41.     }
  42.     #[Route(path'/widgets/menu/offcanvas'name'frontend.menu.offcanvas'defaults: ['XmlHttpRequest' => true'_httpCache' => true], methods: ['GET'])]
  43.     public function offcanvas(Request $requestSalesChannelContext $context): Response
  44.     {
  45.         $page $this->offcanvasLoader->load($request$context);
  46.         $this->hook(new MenuOffcanvasPageletLoadedHook($page$context));
  47.         $response $this->renderStorefront(
  48.             '@Storefront/storefront/layout/navigation/offcanvas/navigation-pagelet.html.twig',
  49.             ['page' => $page]
  50.         );
  51.         $response->headers->set('x-robots-tag''noindex');
  52.         return $response;
  53.     }
  54. }