<?php
declare(strict_types=1);
namespace BitBag\OpenMarketplace\Component\Vendor\Form\Type;
use BitBag\OpenMarketplace\Component\Customer\Model\CustomerInterface;
use BitBag\OpenMarketplace\Component\Organization\Entity\OrganizationInterface;
use BitBag\OpenMarketplace\Component\Organization\Form\Type\OrganizationRegistrationType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class OrganizationVendorRegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options = []): void
{
parent::buildForm($builder, $options);
$builder
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void {
/** @var CustomerInterface $customer */
$customer = $event->getData();
/** @var OrganizationInterface $organization */
$organization = $customer->getOrganization();
/* @todo: properly handle hidden company submission */
$billingData = $organization->getBillingData();
$billingData->setCompany($organization->getName());
$organization->setBillingData($billingData);
$organization->setIsVendorRegister(true);
$customer->setOrganization($organization);
$event->setData($customer);
})
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'validation_groups' => ['hyfindr', 'app_organization_registration'],
]);
}
public function getParent(): string
{
return OrganizationRegistrationType::class;
}
public function getBlockPrefix(): string
{
return 'bitbag_sylius_organization_plugin_organization_vendor_registration';
}
}