<?php declare(strict_types=1);
/**
* gb media
* All Rights Reserved.
*
* Unauthorized copying of this file, via any medium is strictly prohibited.
* The content of this file is proprietary and confidential.
*
* @category Shopware
* @package Shopware_Plugins
* @subpackage GbmedConfigStates
* @copyright Copyright (c) 2020, gb media
* @license proprietary
* @author Giuseppe Bottino
* @link http://www.gb-media.biz
*/
namespace Gbmed\ConfigStates\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Theme implements EventSubscriberInterface
{
/**
* @var SystemConfigService
*/
protected $systemConfig;
private $defaultColors = [
'colorBackgroundNeutral' => '#ffffff',
'colorBorderNeutral' => '#52667a',
'colorColorNeutral' => '#52667a',
'colorBackgroundProgress' => '#26b6cf',
'colorBorderProgress' => '#ffffff',
'colorColorProgress' => '#26b6cf',
'colorBackgroundWaiting' => '#ffe700',
'colorBorderWaiting' => '#26b6cf',
'colorColorWaiting' => '#ffe700',
'colorBackgroundDanger' => '#e52427',
'colorBorderDanger' => '#ffffff',
'colorColorDanger' => '#e52427',
'colorBackgroundSuccess' => '#3cc261',
'colorBorderSuccess' => '#ffffff',
'colorColorSuccess' => '#3cc261',
];
public function __construct(SystemConfigService $systemConfig)
{
$this->systemConfig = $systemConfig;
}
public static function getSubscribedEvents(): array
{
return [
ThemeCompilerEnrichScssVariablesEvent::class => 'onThemeCompilerEnrichScssVariables'
];
}
/**
* @param ThemeCompilerEnrichScssVariablesEvent $event
*/
public function onThemeCompilerEnrichScssVariables(ThemeCompilerEnrichScssVariablesEvent $event): void
{
$colors = $this->systemConfig->get('GbmedConfigStates.config', $event->getSalesChannelId());
if(!is_array($colors)){
$colors = [];
}
foreach ($this->defaultColors as $key => $defaultColor) {
if(!isset($colors[$key])){
$colors[$key] = $defaultColor;
}
}
$event->addVariable('gbmed-config-states-background-neutral', $colors['colorBackgroundNeutral']);
$event->addVariable('gbmed-config-states-border-neutral', $colors['colorBorderNeutral']);
$event->addVariable('gbmed-config-states-color-neutral', $colors['colorColorNeutral']);
$event->addVariable('gbmed-config-states-background-progress', $colors['colorBackgroundProgress']);
$event->addVariable('gbmed-config-states-border-progress', $colors['colorBorderProgress']);
$event->addVariable('gbmed-config-states-color-progress', $colors['colorColorProgress']);
$event->addVariable('gbmed-config-states-background-waiting', $colors['colorBackgroundWaiting']);
$event->addVariable('gbmed-config-states-border-waiting', $colors['colorBorderWaiting']);
$event->addVariable('gbmed-config-states-color-waiting', $colors['colorColorWaiting']);
$event->addVariable('gbmed-config-states-background-danger', $colors['colorBackgroundDanger']);
$event->addVariable('gbmed-config-states-border-danger', $colors['colorBorderDanger']);
$event->addVariable('gbmed-config-states-color-danger', $colors['colorColorDanger']);
$event->addVariable('gbmed-config-states-background-success', $colors['colorBackgroundSuccess']);
$event->addVariable('gbmed-config-states-border-success', $colors['colorBorderSuccess']);
$event->addVariable('gbmed-config-states-color-success', $colors['colorColorSuccess']);
}
}