src/Component/Vendor/Form/Type/OrganizationVendorRegistrationType.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace BitBag\OpenMarketplace\Component\Vendor\Form\Type;
  4. use BitBag\OpenMarketplace\Component\Customer\Model\CustomerInterface;
  5. use BitBag\OpenMarketplace\Component\Organization\Entity\OrganizationInterface;
  6. use BitBag\OpenMarketplace\Component\Organization\Form\Type\OrganizationRegistrationType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\Form\FormEvent;
  10. use Symfony\Component\Form\FormEvents;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. final class OrganizationVendorRegistrationType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options = []): void
  15.     {
  16.         parent::buildForm($builder$options);
  17.         $builder
  18.             ->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void {
  19.                 /** @var CustomerInterface $customer */
  20.                 $customer $event->getData();
  21.                 /** @var OrganizationInterface $organization */
  22.                 $organization $customer->getOrganization();
  23.                 /* @todo: properly handle hidden company submission */
  24.                 $billingData $organization->getBillingData();
  25.                 $billingData->setCompany($organization->getName());
  26.                 $organization->setBillingData($billingData);
  27.                 $organization->setIsVendorRegister(true);
  28.                 $customer->setOrganization($organization);
  29.                 $event->setData($customer);
  30.             })
  31.             ;
  32.     }
  33.     public function configureOptions(OptionsResolver $resolver): void
  34.     {
  35.         $resolver->setDefaults([
  36.             'validation_groups' => ['hyfindr''app_organization_registration'],
  37.         ]);
  38.     }
  39.     public function getParent(): string
  40.     {
  41.         return OrganizationRegistrationType::class;
  42.     }
  43.     public function getBlockPrefix(): string
  44.     {
  45.         return 'bitbag_sylius_organization_plugin_organization_vendor_registration';
  46.     }
  47. }