CoopTilleulsSyliusClickNCollectPlugin icon indicating copy to clipboard operation
CoopTilleulsSyliusClickNCollectPlugin copied to clipboard

ShippingMethodTypeExtension doesn't reference to overrided Location entity

Open kbyjoel opened this issue 4 years ago • 2 comments

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 !

kbyjoel avatar Jul 01 '20 15:07 kbyjoel

Hi ! Thanks for the feedback, could you open a PR please ?

thcolin avatar Oct 12 '20 10:10 thcolin

@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

veloxy avatar Nov 26 '20 10:11 veloxy