custom/plugins/TmmsDropDownMenu/src/Subscriber/ThemeVariablesSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tmms\DropDownMenu\Subscriber;
  4. use Shopware\Core\System\SystemConfig\SystemConfigService;
  5. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  8. use Tmms\DropDownMenu\TmmsDropDownMenu;
  9. class ThemeVariablesSubscriber implements EventSubscriberInterface
  10. {
  11.     private SystemConfigService $systemConfig;
  12.     public function __construct(SystemConfigService $systemConfig)
  13.     {
  14.         $this->systemConfig $systemConfig;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables',
  20.         ];
  21.     }
  22.     public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event): void
  23.     {
  24.         $configFields $this->systemConfig->get('TmmsDropDownMenu.config'$event->getSalesChannelId());
  25.         foreach($configFields as $configKey => $value) {
  26.             // convert `customVariableName` to `custom-variable-name`
  27.             $kebabCasedScssVariable str_replace('_''-', (new CamelCaseToSnakeCaseNameConverter())->normalize($configKey));
  28.             if($value && in_array($configKeyTmmsDropDownMenu::PLUGIN_CONFIG_VARS)) {
  29.                 $event->addVariable(
  30.                     'tmms-' $kebabCasedScssVariable,
  31.                     (string) $value
  32.                 );
  33.             }
  34.         }
  35.     }
  36. }