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

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