custom/plugins/OkeonlineKejeDeliveryDatePicker/src/Storefront/Subscriber/OrderCreateValidationSubscriber.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Okeonline\KejeDeliveryDatePicker\Storefront\Subscriber;
  3. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  4. use Shopware\Core\Framework\Validation\DataValidationDefinition;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Validator\Constraints\NotBlank;
  7. class OrderCreateValidationSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             'framework.validation.order.create' => 'addValidationRules'
  13.         ];
  14.     }
  15.     public function addValidationRules(BuildValidationEvent $event)
  16.     {
  17.         // add a NotBlank validation to the 'sub' oo_checkout_extra_data_, on the field 'ordered_by'
  18.         //  request contains:  oo_checkout_extra_data_[ordered_by]=something
  19.         //  when something is missing, this redirects back to previous page, and flashes a error
  20.         $event->getDefinition()->addSub(
  21.             'oo_checkout_extra_data_',
  22.             (new DataValidationDefinition('oo_checkout_extra_data_'))->add('ordered_by', new NotBlank())
  23.         );
  24.     }
  25. }