vendor/shopware/storefront/Pagelet/Menu/Offcanvas/MenuOffcanvasPageletLoader.php line 41

  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. /**
  12.  * Do not use direct or indirect repository calls in a PageletLoader. Always use a store-api route to get or put data.
  13.  */
  14. #[Package('storefront')]
  15. class MenuOffcanvasPageletLoader implements MenuOffcanvasPageletLoaderInterface
  16. {
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(
  21.         private readonly EventDispatcherInterface $eventDispatcher,
  22.         private readonly NavigationLoaderInterface $navigationLoader
  23.     ) {
  24.     }
  25.     /**
  26.      * @throws CategoryNotFoundException
  27.      * @throws InconsistentCriteriaIdsException
  28.      * @throws MissingRequestParameterException
  29.      */
  30.     public function load(Request $requestSalesChannelContext $context): MenuOffcanvasPagelet
  31.     {
  32.         $navigationId = (string) $request->query->get('navigationId'$context->getSalesChannel()->getNavigationCategoryId());
  33.         if (!$navigationId) {
  34.             throw new MissingRequestParameterException('navigationId');
  35.         }
  36.         $navigation $this->navigationLoader->load($navigationId$context$navigationId1);
  37.         $pagelet = new MenuOffcanvasPagelet($navigation);
  38.         $this->eventDispatcher->dispatch(
  39.             new MenuOffcanvasPageletLoadedEvent($pagelet$context$request)
  40.         );
  41.         return $pagelet;
  42.     }
  43. }