<?php declare(strict_types=1);
namespace ImnxxNavigationBanner\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ThemeVariableSubscriber implements EventSubscriberInterface
{
protected SystemConfigService $systemConfig;
public function __construct(SystemConfigService $systemConfig)
{
$this->systemConfig = $systemConfig;
}
public static function getSubscribedEvents(): array
{
return [
ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
];
}
public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event): void
{
$configPluginNavigationBannerBgColor = $this->systemConfig->get('ImnxxNavigationBanner.config.navigationBannerBackgroundColor', $event->getSalesChannelId());
$configPluginNavigationBannerTextColor = $this->systemConfig->get('ImnxxNavigationBanner.config.navigationBannerTextColor', $event->getSalesChannelId());
if ($configPluginNavigationBannerBgColor) {
$event->addVariable('imnxx-navigation-banner-bg-color', $configPluginNavigationBannerBgColor);
}
if ($configPluginNavigationBannerTextColor) {
$event->addVariable('imnxx-navigation-banner-text-color', $configPluginNavigationBannerTextColor);
}
}
}