Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract base form types for every entity used in AdminBundle #16257

Merged
merged 15 commits into from
May 23, 2024
Merged
Prev Previous commit
Next Next commit
Extract admin-only ZoneType
  • Loading branch information
TheMilek committed May 22, 2024
commit aa30003d380224c742c08380f6d7632fdd4ef197

This file was deleted.

23 changes: 21 additions & 2 deletions src/Sylius/Bundle/AdminBundle/Form/Type/ZoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,33 @@

namespace Sylius\Bundle\AdminBundle\Form\Type;

use Sylius\Bundle\AddressingBundle\Form\Type\ZoneMemberType;
use Sylius\Bundle\AddressingBundle\Form\Type\ZoneType as BaseZoneType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;

final class ZoneType extends AbstractType
{
public function getBlockPrefix(): string
public function buildForm(FormBuilderInterface $builder, array $options): void
{
return 'sylius_admin_zone';
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
$entryOptions = $event->getForm()->get('members')->getConfig()->getOptions()['entry_options'];

$event->getForm()->add('members', LiveCollectionType::class, [
'entry_type' => ZoneMemberType::class,
'entry_options' => $entryOptions,
'button_add_options' => [
'label' => 'sylius.form.zone.add_member',
],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'delete_empty' => true,
]);
});
}

public function getParent(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sylius_admin_zone:
except: ['show', 'create']
redirect: update
grid: sylius_admin_zone
form:
type: Sylius\Bundle\AdminBundle\Form\Type\ZoneType
permission: true
vars:
all:
Expand All @@ -25,6 +27,8 @@ sylius_admin_zone_create:
method: createTyped
arguments:
type: $type
form:
type: Sylius\Bundle\AdminBundle\Form\Type\ZoneType
template: "@SyliusAdmin/shared/crud/create.html.twig"
redirect: sylius_admin_zone_update
permission: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<tag name="form.type_extension" extended-type="Sylius\Bundle\AddressingBundle\Form\Type\AddressType" priority="100" />
</service>

<service id="Sylius\Bundle\AdminBundle\Form\Extension\ZoneTypeExtension">
<tag name="form.type_extension" extended-type="Sylius\Bundle\AddressingBundle\Form\Type\ZoneType" priority="100" />
<service id="sylius_admin.form.type.zone" class="Sylius\Bundle\AdminBundle\Form\Type\ZoneType">
<tag name="form.type" />
</service>

<service id="sylius_admin.form.type.catalog_promotion_scope" class="Sylius\Bundle\AdminBundle\Form\Type\CatalogPromotionScopeType">
Expand Down