<?php declare(strict_types=1);
namespace CoeRechnungsMailSw6\Subscriber;
use Shopware\Core\Framework\Validation\BuildValidationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
/**
* Class ValidationSubscriber
* @package CoeRechnungsMailSw6\Subscriber
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
Class ValidationSubscriber implements EventSubscriberInterface{
/** @var SystemConfigService $systemConfigService*/
private $systemConfigService;
/**
* ValidationSubscriber constructor.
* @param SystemConfigService $systemConfigService
*/
function __construct(SystemConfigService $systemConfigService)
{
$this -> systemConfigService = $systemConfigService;
}
/**
* @return array
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
public static function getSubscribedEvents(): array
{
return [
'framework.validation.customer.create' => 'addDocumentMailValidation',
'framework.validation.customer.profile.update' => 'addDocumentMailValidation',
];
}
/**
* When invoice email field is set, we need to validate the given email address
* @param BuildValidationEvent $event
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
public function addDocumentMailValidation(BuildValidationEvent $event)
{
if(!$event->getData()->get("documentMail")){
return;
}
$event->getDefinition()->add('documentMail', new Email());
}
}