<?php
declare(strict_types=1);
namespace CioFrontendCss\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Event\StorefrontRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CioFrontendCssSubscriber implements EventSubscriberInterface
{
/**
* @var SystemConfigService
*/
private SystemConfigService $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents(): array
{
return [
StorefrontRenderEvent::class => 'onStorefrontRender'
];
}
public function onStorefrontRender(StorefrontRenderEvent $event)
{
$moduleActive = $this->systemConfigService->get('CioFrontendCss.config.active', $event->getSalesChannelContext()->getSalesChannelId());
$cioFrontendCss = '';
$cioFrontendHeadHtml = '';
$cioFrontendFooterHtml = '';
if ($moduleActive) {
$cioFrontendCss = $this->systemConfigService->get('CioFrontendCss.config.cssStyles', $event->getSalesChannelContext()->getSalesChannelId());
$cioFrontendHeadHtml = $this->systemConfigService->get('CioFrontendCss.config.headHtmlCode', $event->getSalesChannelContext()->getSalesChannelId());
$cioFrontendFooterHtml = $this->systemConfigService->get('CioFrontendCss.config.footerHtmlCode', $event->getSalesChannelContext()->getSalesChannelId());
}
$event->setParameter('cioFrontendCssActive', $moduleActive);
$event->setParameter('cioFrontendCssStyles', $cioFrontendCss);
$event->setParameter('cioFrontendHeadHtml', $cioFrontendHeadHtml);
$event->setParameter('cioFrontendFooterHtml', $cioFrontendFooterHtml);
}
}