custom/plugins/IronHoliday/src/Subscriber/ThemeVariablesSubscriber.php line 47

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace IronHoliday\Subscriber;
  3. use IronHoliday\Holiday\HolidayDataService;
  4. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. /**
  7.  * Class ThemeVariablesSubscriber
  8.  *
  9.  * @package IronHoliday\Subscriber
  10.  */
  11. class ThemeVariablesSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var HolidayDataService
  15.      */
  16.     private $holidayDataService;
  17.     /**
  18.      * PluginSettingsSubscriber constructor.
  19.      *
  20.      * @param HolidayDataService $holidayDataService
  21.      */
  22.     public function __construct(
  23.         HolidayDataService $holidayDataService
  24.     )
  25.     {
  26.         $this->holidayDataService $holidayDataService;
  27.     }
  28.     /*
  29.      * @inherit
  30.      */
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
  35.         ];
  36.     }
  37.     /**
  38.      * @param ThemeCompilerEnrichScssVariablesEvent $event
  39.      * @throws \Exception
  40.      */
  41.     public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
  42.     {
  43.         $holidayData $this->holidayDataService->getHolidayData($event->getSalesChannelId());
  44.         if ($holidayData->getFrameColor()) {
  45.             $event->addVariable('iron-holiday-frame-color'$holidayData->getFrameColor());
  46.         }
  47.         if ($holidayData->getBackgroundColor()) {
  48.             $event->addVariable('iron-holiday-background-color'$holidayData->getBackgroundColor());
  49.         }
  50.         if ($holidayData->getFontColor()) {
  51.             $event->addVariable('iron-holiday-font-color'$holidayData->getFontColor());
  52.         }
  53.     }
  54. }