src/Storefront/Pagelet/Menu/Offcanvas/MenuOffcanvasPageletLoader.php line 36

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Pagelet\Menu\Offcanvas;
  3. use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
  4. use Shopware\Core\Content\Category\Service\NavigationLoaderInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. #[Package('storefront')]
  12. class MenuOffcanvasPageletLoader implements MenuOffcanvasPageletLoaderInterface
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly NavigationLoaderInterface $navigationLoader)
  18.     {
  19.     }
  20.     /**
  21.      * @throws CategoryNotFoundException
  22.      * @throws InconsistentCriteriaIdsException
  23.      * @throws MissingRequestParameterException
  24.      */
  25.     public function load(Request $requestSalesChannelContext $context): MenuOffcanvasPagelet
  26.     {
  27.         $navigationId = (string) $request->query->get('navigationId'$context->getSalesChannel()->getNavigationCategoryId());
  28.         if (!$navigationId) {
  29.             throw new MissingRequestParameterException('navigationId');
  30.         }
  31.         $navigation $this->navigationLoader->load($navigationId$context$navigationId1);
  32.         $pagelet = new MenuOffcanvasPagelet($navigation);
  33.         $this->eventDispatcher->dispatch(
  34.             new MenuOffcanvasPageletLoadedEvent($pagelet$context$request)
  35.         );
  36.         return $pagelet;
  37.     }
  38. }