<?php declare(strict_types=1);
namespace IronHoliday\Subscriber;
use IronHoliday\Holiday\HolidayDataService;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ThemeVariablesSubscriber
*
* @package IronHoliday\Subscriber
*/
class ThemeVariablesSubscriber implements EventSubscriberInterface
{
/**
* @var HolidayDataService
*/
private $holidayDataService;
/**
* PluginSettingsSubscriber constructor.
*
* @param HolidayDataService $holidayDataService
*/
public function __construct(
HolidayDataService $holidayDataService
)
{
$this->holidayDataService = $holidayDataService;
}
/*
* @inherit
*/
public static function getSubscribedEvents(): array
{
return [
ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
];
}
/**
* @param ThemeCompilerEnrichScssVariablesEvent $event
* @throws \Exception
*/
public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
{
$holidayData = $this->holidayDataService->getHolidayData($event->getSalesChannelId());
if ($holidayData->getFrameColor()) {
$event->addVariable('iron-holiday-frame-color', $holidayData->getFrameColor());
}
if ($holidayData->getBackgroundColor()) {
$event->addVariable('iron-holiday-background-color', $holidayData->getBackgroundColor());
}
if ($holidayData->getFontColor()) {
$event->addVariable('iron-holiday-font-color', $holidayData->getFontColor());
}
}
}