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

ShippingMethodTypeExtension doesn't reference to overrided Location entity #33

Open
kbyjoel opened this issue Jul 1, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@kbyjoel
Copy link

kbyjoel commented Jul 1, 2020

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 !

@toofff toofff added the bug Something isn't working label Oct 12, 2020
@thcolin
Copy link
Contributor

thcolin commented Oct 12, 2020

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

@veloxy
Copy link
Contributor

veloxy commented Nov 26, 2020

@thcolin I opened a PR that fixes this, and some other places where the entity is used instead of the interface
#54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants