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

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