src/Form/EventSubscriber/Quote/CustomerSubscriber.php line 33

  1. <?php
  2. namespace App\Form\EventSubscriber\Quote;
  3. use App\Entity\Addressing\Country;
  4. use App\Form\Type\Customer\CustomerForQuoteType;
  5. use App\Repository\Addressing\CountryRepository;
  6. use Sylius\Bundle\CustomerBundle\Form\Type\CustomerType;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Form\Extension\Core\Type\TelType;
  10. use Symfony\Component\Form\FormEvent;
  11. use Symfony\Component\Form\FormEvents;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. class CustomerSubscriber implements EventSubscriberInterface
  14. {
  15.     
  16.     private $tokenStorage;
  17.     public function __construct(TokenStorageInterface $tokenStorageInterface)
  18.     {
  19.         $this->tokenStorage $tokenStorageInterface
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         // Tells the dispatcher that you want to listen on the form.pre_set_data
  24.         // event and that the preSetData method should be called.
  25.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  26.     }
  27.     public function preSetData(FormEvent $event)
  28.     {
  29.         $data $event->getData();
  30.         $form $event->getForm();  
  31.         
  32.         if (!$this->tokenStorage->getToken()) { 
  33.             $form 
  34.                 ->add('customer',CustomerForQuoteType::class)
  35.                 ;
  36.         }
  37.     }
  38. }