custom/plugins/CoeRechnungsMailSw6/src/Subscriber/ValidationSubscriber.php line 48

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace CoeRechnungsMailSw6\Subscriber;
  3. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\Validator\Constraints\Email;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. /**
  10.  * Class ValidationSubscriber
  11.  * @package CoeRechnungsMailSw6\Subscriber
  12.  * @author Jeffry Block <jeffry.block@codeenterprise.de>
  13.  */
  14. Class ValidationSubscriber implements EventSubscriberInterface{
  15.     /** @var SystemConfigService $systemConfigService*/
  16.     private $systemConfigService;
  17.     /**
  18.      * ValidationSubscriber constructor.
  19.      * @param SystemConfigService $systemConfigService
  20.      */
  21.     function __construct(SystemConfigService $systemConfigService)
  22.     {
  23.         $this -> systemConfigService $systemConfigService;
  24.     }
  25.     /**
  26.      * @return array
  27.      * @author Jeffry Block <jeffry.block@codeenterprise.de>
  28.      */
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             'framework.validation.customer.create' => 'addDocumentMailValidation',
  33.             'framework.validation.customer.profile.update' => 'addDocumentMailValidation',
  34.         ];
  35.     }
  36.     /**
  37.      * When invoice email field is set, we need to validate the given email address
  38.      * @param BuildValidationEvent $event
  39.      * @author Jeffry Block <jeffry.block@codeenterprise.de>
  40.      */
  41.     public function addDocumentMailValidation(BuildValidationEvent $event)
  42.     {
  43.         if(!$event->getData()->get("documentMail")){
  44.             return;
  45.         }
  46.         $event->getDefinition()->add('documentMail', new Email());
  47.     }
  48. }