<?php declare(strict_types=1);
namespace Verign\VerignFeedback\Storefront\Subscriber;
use Verign\VerignFeedback\Components\StorefrontFitter;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Verign\VerignFeedback\Components\FeedbackCaptcha;
class FeedbackSubscriber implements EventSubscriberInterface {
private $systemConfigService;
/**
* @var FeedbackCaptcha
*/
private $fCaptcha;
public function __construct(SystemConfigService $systemConfigService, FeedbackCaptcha $fCaptcha)
{
$this->systemConfigService = $systemConfigService;
$this->fCaptcha = $fCaptcha;
}
public static function getSubscribedEvents() : array
{
return[
HeaderPageletLoadedEvent::class => 'addConfigInformations',
ThemeCompilerEnrichScssVariablesEvent::class => 'addScssVariables'
];
}
public function addConfigInformations(HeaderPageletLoadedEvent $event) {
$config = $this->systemConfigService->get('VerignFeedback.config',
$event->getSalesChannelContext()->getSalesChannel()->getId());
if(key_exists('isActivated', $config) && $config['isActivated'] === true){
$sf = new StorefrontFitter();
//die(var_dump($config));
if(key_exists('hasCaptcha', $config) && $config['hasCaptcha'] === true){
$config['imgBase64'] = $this->fCaptcha->generateCaptcha();
}
$sf->setArray($config);
$event->getPagelet()->addExtension("vfeedbackConfig", $sf);
}
}
public function addScssVariables(ThemeCompilerEnrichScssVariablesEvent $event){
// Will render: $sass-plugin-name-color: #ffcc59;
$event->addVariable('sass-plugin-name-color', '#ffcc59');
}
}