src/Form/EventListener/User/AddQoodosSubscriptionFieldSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\User;
  4. use App\Entity\Security\Customer;
  5. use App\Entity\Security\ShopManager;
  6. use App\Form\FormHelper;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\FormEvent;
  10. use Symfony\Component\Form\FormEvents;
  11. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  12. class AddQoodosSubscriptionFieldSubscriber extends FormHelper implements EventSubscriberInterface
  13. {
  14.     public function __construct(
  15.         private TokenStorageInterface $tokenStorage,
  16.     ) {
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  21.     }
  22.     public function preSetData(FormEvent $event): void
  23.     {
  24.         /** @var Customer */
  25.         $customer $event->getData();
  26.         /** @var ShopManager */
  27.         $currentUser $this->tokenStorage->getToken()->getUser();
  28.         if (
  29.             true === $customer instanceof Customer
  30.             && null === $customer->getId()
  31.             && true === $currentUser instanceof ShopManager
  32.             && null !== $currentUser->getShop()
  33.         ) {
  34.             $event->getForm()->add('qoodosSubscription'CheckboxType::class, $this->getCheckParameters('app.global.user.list.qoodos.subscription'self::PLACEHOLDER_ENABLE_ASK));
  35.         }
  36.     }
  37. }