platform/src/Storefront/Controller/NavigationController.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Controller;
  3. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  4. use Shopware\Core\Framework\Routing\Annotation\Since;
  5. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  6. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  7. use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
  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.  * @RouteScope(scopes={"storefront"})
  14.  */
  15. class NavigationController extends StorefrontController
  16. {
  17.     private NavigationPageLoaderInterface $navigationPageLoader;
  18.     private MenuOffcanvasPageletLoaderInterface $offcanvasLoader;
  19.     public function __construct(
  20.         NavigationPageLoaderInterface $navigationPageLoader,
  21.         MenuOffcanvasPageletLoaderInterface $offcanvasLoader
  22.     ) {
  23.         $this->navigationPageLoader $navigationPageLoader;
  24.         $this->offcanvasLoader $offcanvasLoader;
  25.     }
  26.     /**
  27.      * @Since("6.0.0.0")
  28.      * @HttpCache()
  29.      * @Route("/", name="frontend.home.page", options={"seo"="true"}, methods={"GET"})
  30.      */
  31.     public function home(Request $requestSalesChannelContext $context): ?Response
  32.     {
  33.         $page $this->navigationPageLoader->load($request$context);
  34.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  35.     }
  36.     /**
  37.      * @Since("6.3.3.0")
  38.      * @HttpCache()
  39.      * @Route("/navigation/{navigationId}", name="frontend.navigation.page", options={"seo"=true}, methods={"GET"})
  40.      */
  41.     public function index(SalesChannelContext $contextRequest $request): Response
  42.     {
  43.         $page $this->navigationPageLoader->load($request$context);
  44.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  45.     }
  46.     /**
  47.      * @Since("6.0.0.0")
  48.      * @HttpCache()
  49.      * @Route("/widgets/menu/offcanvas", name="frontend.menu.offcanvas", methods={"GET"}, defaults={"XmlHttpRequest"=true})
  50.      */
  51.     public function offcanvas(Request $requestSalesChannelContext $context): Response
  52.     {
  53.         $page $this->offcanvasLoader->load($request$context);
  54.         $response $this->renderStorefront(
  55.             '@Storefront/storefront/layout/navigation/offcanvas/navigation-pagelet.html.twig',
  56.             ['page' => $page]
  57.         );
  58.         $response->headers->set('x-robots-tag''noindex');
  59.         return $response;
  60.     }
  61. }