CoopTilleulsSyliusClickNCollectPlugin
CoopTilleulsSyliusClickNCollectPlugin copied to clipboard
ShippingMethodTypeExtension doesn't reference to overrided Location entity
Hi ! Just found a bug:
When you override Location entity, the ShippingMethodTypeExtension
still reference CoopTilleuls\SyliusClickNCollectPlugin\Entity\Location
The form extension service should get the location class as argument in services.xml:
<service id="coop_tilleuls_click_n_collect.form.extension.type.shipping_method" class="CoopTilleuls\SyliusClickNCollectPlugin\Form\Extension\ShippingMethodTypeExtension">
<argument>%coop_tilleuls_click_n_collect.model.location.class%</argument>
<tag name="form.type_extension" />
</service>
And the form extension should use it:
use Doctrine\ORM\EntityRepository;
use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @author Kévin Dunglas <[email protected]>
*/
final class ShippingMethodTypeExtension extends AbstractTypeExtension
{
/** @var string */
private $className;
/**
* ShippingMethodTypeExtension constructor.
* @param string $className
*/
public function __construct(string $className)
{
$this->className = $className;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('locations', EntityType::class, [
'class' => $this->className,
'required' => false,
'multiple' => true,
'expanded' => true,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->orderBy('p.name', 'ASC');
},
'choice_label' => 'name',
'label' => 'coop_tilleuls_click_n_collect.form.shipping_method.locations',
]);
}
public static function getExtendedTypes(): iterable
{
return [ShippingMethodType::class];
}
}
Tell me if you need me to open a PR, Have a good day !
Hi ! Thanks for the feedback, could you open a PR please ?
@thcolin I opened a PR that fixes this, and some other places where the entity is used instead of the interface https://github.com/coopTilleuls/CoopTilleulsSyliusClickNCollectPlugin/pull/54