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

Open in your IDE?
  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\NavigationLoader;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  6. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. class MenuOffcanvasPageletLoader implements MenuOffcanvasPageletLoaderInterface
  11. {
  12.     /**
  13.      * @var EventDispatcherInterface
  14.      */
  15.     private $eventDispatcher;
  16.     /**
  17.      * @var NavigationLoader
  18.      */
  19.     private $navigationLoader;
  20.     public function __construct(EventDispatcherInterface $eventDispatcherNavigationLoader $navigationLoader)
  21.     {
  22.         $this->eventDispatcher $eventDispatcher;
  23.         $this->navigationLoader $navigationLoader;
  24.     }
  25.     /**
  26.      * @throws CategoryNotFoundException
  27.      * @throws InconsistentCriteriaIdsException
  28.      * @throws MissingRequestParameterException
  29.      */
  30.     public function load(Request $requestSalesChannelContext $salesChannelContext): MenuOffcanvasPagelet
  31.     {
  32.         $navigationId $request->query->get('navigationId'$salesChannelContext->getSalesChannel()->getNavigationCategoryId());
  33.         if (!$navigationId) {
  34.             throw new MissingRequestParameterException('navigationId');
  35.         }
  36.         $navigation $this->navigationLoader->loadLevel($navigationId$salesChannelContext);
  37.         $pagelet = new MenuOffcanvasPagelet($navigation);
  38.         $this->eventDispatcher->dispatch(
  39.             new MenuOffcanvasPageletLoadedEvent($pagelet$salesChannelContext$request)
  40.         );
  41.         return $pagelet;
  42.     }
  43. }