custom/plugins/zenitPlatformFeaturesBar/src/Subscriber/ThemeVariablesSubscriber.php line 34

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformFeaturesBar\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ThemeVariablesSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var string
  10.      */
  11.     private $configPath 'zenitPlatformFeaturesBar.config.';
  12.     /**
  13.      * @var SystemConfigService
  14.      */
  15.     protected $systemConfig;
  16.     // add the `SystemConfigService` to your constructor
  17.     public function __construct(SystemConfigService $systemConfig)
  18.     {
  19.         $this->systemConfig $systemConfig;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
  25.         ];
  26.     }
  27.     public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
  28.     {
  29.         $shopId $event->getSalesChannelId();
  30.         /**
  31.          * @var string $fontSize
  32.          * @var string $textColor
  33.          * @var string $textColorHover
  34.          * @var string $backgroundColor
  35.          * @var string $columnBackgroundColor
  36.          */
  37.         $fontSize $this->systemConfig->get($this->configPath 'fontSize'$shopId);
  38.         $textColor $this->systemConfig->get($this->configPath 'textColor'$shopId);
  39.         $textColorHover $this->systemConfig->get($this->configPath 'textColorHover'$shopId);
  40.         $backgroundColor $this->systemConfig->get($this->configPath 'backgroundColor'$shopId);
  41.         $columnBackgroundColor $this->systemConfig->get($this->configPath 'columnBackgroundColor'$shopId);
  42.         /**
  43.          * @var string $borderRadius
  44.          */
  45.         $borderRadius $this->systemConfig->get($this->configPath 'borderRadius'$shopId) ?? '0';
  46.         /**
  47.          * @var string $fontSize
  48.          * @var string $iconFont
  49.          */
  50.         $iconSize $this->systemConfig->get($this->configPath 'iconSize'$shopId);
  51.         $iconFont $this->systemConfig->get($this->configPath 'iconFont'$shopId);
  52.         /**
  53.          * @var string $padding
  54.          */
  55.         $padding $this->systemConfig->get($this->configPath 'padding'$shopId) ?? '0';
  56.         $event->addVariable('zen-features-bar-font-size'$fontSize 'px');
  57.         $event->addVariable('zen-features-bar-text-color'$textColor);
  58.         $event->addVariable('zen-features-bar-text-color-hover'$textColorHover);
  59.         $event->addVariable('zen-features-bar-background-color'$backgroundColor);
  60.         $event->addVariable('zen-features-bar-background-color-column'$columnBackgroundColor);
  61.         $event->addVariable('zen-features-bar-border-radius'$borderRadius 'px');
  62.         $event->addVariable('zen-features-bar-icon-size'$iconSize 'px');
  63.         $event->addVariable('zen-features-bar-icon-font'$iconFont);
  64.         $event->addVariable('zen-features-bar-padding'$padding 'px');
  65.         $event->addVariable('zen-features-bar-element-height', ($padding 2) + ($fontSize 1.5) . 'px');
  66.     }
  67. }