custom/plugins/AvencyShopwareCms/src/Core/Subscriber/ScssSubscriber.php line 41

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Avency\Shopware\Cms\Core\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  7. class ScssSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var SystemConfigService
  11.      */
  12.     protected $systemConfigService;
  13.     public function __construct(SystemConfigService $systemConfigService)
  14.     {
  15.         $this->systemConfigService $systemConfigService;
  16.     }
  17.     /**
  18.      * Returns subscribed events
  19.      *
  20.      * @return array|string[]
  21.      */
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             ThemeCompilerEnrichScssVariablesEvent::class => 'addScssVariables'
  26.         ];
  27.     }
  28.     /**
  29.      * Add scss variables
  30.      *
  31.      * @param ThemeCompilerEnrichScssVariablesEvent $event
  32.      * @return void
  33.      */
  34.     public function addScssVariables(ThemeCompilerEnrichScssVariablesEvent $event): void
  35.     {
  36.         $config $this->systemConfigService->get('AvencyShopwareCms.config'$event->getSalesChannelId());
  37.         if ($config['colorsActive']) {
  38.             foreach ($config as $key => $value) {
  39.                 $variable str_replace('_''-', (new CamelCaseToSnakeCaseNameConverter())->normalize($key));
  40.                 if (strpos($variable'avency') !== false && strpos($value'#') !== false) {
  41.                     $event->addVariable($variable$value);
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }