<?php declare(strict_types=1);
namespace Cogi\MobileMenu\Subscriber;
use Shopware\Core\Content\Category\Service\NavigationLoaderInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Event\StorefrontRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MobileMenuSubscriber implements EventSubscriberInterface
{
/**
* @var NavigationLoaderInterface
*/
private $navigationLoader;
/**
* @var SystemConfigService
*/
private $systemConfigService;
/**
* @param NavigationLoaderInterface $navigationLoader
* @param SystemConfigService $systemConfigService
*/
public function __construct(
NavigationLoaderInterface $navigationLoader,
SystemConfigService $systemConfigService
)
{
$this->navigationLoader = $navigationLoader;
$this->systemConfigService = $systemConfigService;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
StorefrontRenderEvent::class => 'addMobileMenuFooterMenu'
];
}
public function addMobileMenuFooterMenu(StorefrontRenderEvent $event)
{
$navigationId = $this->systemConfigService->get('CogiMobileMenu.config.footerNavigationEntryPoint');
if ($navigationId) {
$tree = $this->navigationLoader->load($navigationId, $event->getSalesChannelContext(), $navigationId);
$event->setParameter('cogiMobileMenuFooterNavigationEntryPoint', $tree);
}
}
}