shopware5/devdocs

Address Management Guide not valid for Shopware >= v5.5

AlexBachmann opened this issue · 1 comments

In the Address Management Guide (https://developers.shopware.com/developers-guide/address-management-guide/#extending-the-address-form) the following script is given for the FormBuilder Subscriber:

// PluginFolder/Subscriber/FormExtenderSubscriber.php

public static function getSubscribedEvents()
{
    return [
        'Shopware_Form_Builder' => 'onFormBuild',
    ];
}
    
public function onFormBuild(\Enlight_Event_EventArgs $event)
{
    if ($event->getReference() !== \Shopware\Bundle\AccountBundle\Form\Account\AddressFormType::class) {
        return;
    }

    /** @var \Symfony\Component\Form\FormBuilderInterface $builder */
    $builder = $event->getBuilder();

    $builder->get('additional')
            ->add('neighboursName', \Symfony\Component\Form\Extension\Core\Type\TextType::class, [
                'constraints' => [
                    new \Symfony\Component\Validator\Constraints\NotBlank()
                ]
            ]);
}

This will not work in Shopware v5.5 and higher, since the reference given to the $event is no longer the FormType class but the value of the FormTypes block value.

The correct way to check if the correct FormType is addressed by the FormBuilder should therefore be:

if ($event->getReference() !== 'address') {
        return;
}

Fixed with #1116