forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ProductAssociationType instead of extension
- Loading branch information
Showing
5 changed files
with
72 additions
and
47 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
src/Sylius/Bundle/AdminBundle/Form/Extension/ProductAssociationsTypeExtension.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Sylius/Bundle/AdminBundle/Form/Type/ProductAssociationsType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters