Skip to content

Commit

Permalink
Use ProductAssociationType instead of extension
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek authored and GSadee committed May 8, 2024
1 parent 165b84c commit eff1c8f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Bundle\AdminBundle\Form\Extension;

use Sylius\Bundle\AdminBundle\Form\Type\ProductAssociationsType;
use Sylius\Bundle\CoreBundle\Form\Type\Product\ProductImageType;
use Sylius\Bundle\ProductBundle\Form\Type\ProductType;
use Symfony\Component\Form\AbstractTypeExtension;
Expand All @@ -36,6 +37,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'sylius.form.product.images',
'block_name' => 'entry',
])
->add('associations', ProductAssociationsType::class, [
'label' => false,
])
;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Form\Type;

use Doctrine\Common\Collections\Collection;
use Sylius\Bundle\ProductBundle\Form\Type\ProductAssociationsType as BaseProductAssociationsType;
use Sylius\Component\Product\Model\ProductAssociationInterface;
use Sylius\Component\Product\Model\ProductAssociationTypeInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ProductAssociationsType extends AbstractType
{
/**
* @param DataTransformerInterface<Collection<array-key, ProductAssociationInterface>, Collection<array-key, ProductInterface>> $productsToProductAssociationsTransformer
*/
public function __construct(
private readonly DataTransformerInterface $productsToProductAssociationsTransformer,
) {
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->resetModelTransformers();
$builder->addModelTransformer($this->productsToProductAssociationsTransformer);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'entry_type' => ProductAutocompleteChoiceType::class,
'entry_options' => fn (ProductAssociationTypeInterface $productAssociationType) => [
'label' => $productAssociationType->getName(),
'multiple' => true,
],
]);
}

public function getParent(): string
{
return BaseProductAssociationsType::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<tag name="form.type_extension" />
</service>

<service id="sylius.form.extension.type.product_image" class="Sylius\Bundle\AdminBundle\Form\Extension\ProductImageTypeExtension">
<argument>%sylius.model.product_variant.class%</argument>
<tag name="form.type_extension" />
</service>

<service id="sylius_admin.form.extension.type.channel" class="Sylius\Bundle\AdminBundle\Form\Extension\ChannelTypeExtension">
<tag name="form.type_extension" extended-type="Sylius\Bundle\ChannelBundle\Form\Type\ChannelType" priority="50" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
<tag name="form.type_extension" />
</service>

<service id="sylius_admin.form.extension.type.product_associations" class="Sylius\Bundle\AdminBundle\Form\Extension\ProductAssociationsTypeExtension">
<tag name="form.type_extension" />
<service id="sylius_admin.form.type.product_associations" class="Sylius\Bundle\AdminBundle\Form\Type\ProductAssociationsType">
<argument type="service" id="sylius_admin.form.type.data_transformer.products_to_product_associations" />
<tag name="form.type" />
</service>

<service id="sylius.form.extension.type.product_image" class="Sylius\Bundle\AdminBundle\Form\Extension\ProductImageTypeExtension">
<argument>%sylius.model.product_variant.class%</argument>
<tag name="form.type_extension" />
<service id="sylius_admin.form.type.data_transformer.products_to_product_associations" class="Sylius\Bundle\AdminBundle\Form\DataTransformer\ProductsToProductAssociationsTransformer">
<argument type="service" id="sylius.factory.product_association" />
<argument type="service" id="sylius.repository.product_association_type" />
</service>
</services>
</container>

0 comments on commit eff1c8f

Please sign in to comment.