custom/plugins/GbmedConfigStates/src/Subscriber/Theme.php line 64

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedConfigStates
  12.  * @copyright      Copyright (c) 2020, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\ConfigStates\Subscriber;
  18. use Shopware\Core\System\SystemConfig\SystemConfigService;
  19. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. class Theme implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var SystemConfigService
  25.      */
  26.     protected $systemConfig;
  27.     private $defaultColors = [
  28.         'colorBackgroundNeutral' => '#ffffff',
  29.         'colorBorderNeutral' => '#52667a',
  30.         'colorColorNeutral' => '#52667a',
  31.         'colorBackgroundProgress' => '#26b6cf',
  32.         'colorBorderProgress' => '#ffffff',
  33.         'colorColorProgress' => '#26b6cf',
  34.         'colorBackgroundWaiting' => '#ffe700',
  35.         'colorBorderWaiting' => '#26b6cf',
  36.         'colorColorWaiting' => '#ffe700',
  37.         'colorBackgroundDanger' => '#e52427',
  38.         'colorBorderDanger' => '#ffffff',
  39.         'colorColorDanger' => '#e52427',
  40.         'colorBackgroundSuccess' => '#3cc261',
  41.         'colorBorderSuccess' => '#ffffff',
  42.         'colorColorSuccess' => '#3cc261',
  43.     ];
  44.     public function __construct(SystemConfigService $systemConfig)
  45.     {
  46.         $this->systemConfig $systemConfig;
  47.     }
  48.     public static function getSubscribedEvents(): array
  49.     {
  50.         return [
  51.             ThemeCompilerEnrichScssVariablesEvent::class => 'onThemeCompilerEnrichScssVariables'
  52.         ];
  53.     }
  54.     /**
  55.      * @param ThemeCompilerEnrichScssVariablesEvent $event
  56.      */
  57.     public function onThemeCompilerEnrichScssVariables(ThemeCompilerEnrichScssVariablesEvent $event): void
  58.     {
  59.         $colors $this->systemConfig->get('GbmedConfigStates.config'$event->getSalesChannelId());
  60.         if(!is_array($colors)){
  61.             $colors = [];
  62.         }
  63.         foreach ($this->defaultColors as $key => $defaultColor) {
  64.             if(!isset($colors[$key])){
  65.                 $colors[$key] = $defaultColor;
  66.             }
  67.         }
  68.         $event->addVariable('gbmed-config-states-background-neutral'$colors['colorBackgroundNeutral']);
  69.         $event->addVariable('gbmed-config-states-border-neutral'$colors['colorBorderNeutral']);
  70.         $event->addVariable('gbmed-config-states-color-neutral'$colors['colorColorNeutral']);
  71.         $event->addVariable('gbmed-config-states-background-progress'$colors['colorBackgroundProgress']);
  72.         $event->addVariable('gbmed-config-states-border-progress'$colors['colorBorderProgress']);
  73.         $event->addVariable('gbmed-config-states-color-progress'$colors['colorColorProgress']);
  74.         $event->addVariable('gbmed-config-states-background-waiting'$colors['colorBackgroundWaiting']);
  75.         $event->addVariable('gbmed-config-states-border-waiting'$colors['colorBorderWaiting']);
  76.         $event->addVariable('gbmed-config-states-color-waiting'$colors['colorColorWaiting']);
  77.         $event->addVariable('gbmed-config-states-background-danger'$colors['colorBackgroundDanger']);
  78.         $event->addVariable('gbmed-config-states-border-danger'$colors['colorBorderDanger']);
  79.         $event->addVariable('gbmed-config-states-color-danger'$colors['colorColorDanger']);
  80.         $event->addVariable('gbmed-config-states-background-success'$colors['colorBackgroundSuccess']);
  81.         $event->addVariable('gbmed-config-states-border-success'$colors['colorBorderSuccess']);
  82.         $event->addVariable('gbmed-config-states-color-success'$colors['colorColorSuccess']);
  83.     }
  84. }