OroCommerce Forums

Covering OroCommerce topics, including community updates and company announcements.

Forums OroCommerce How to Override Entity (Custom Customer Register Form)

This topic contains 1 reply, has 2 voices, and was last updated by Andrey Yatsenko Andrey Yatsenko 6 months, 3 weeks ago.

  • Creator
    Topic
  • #37620
    fudu
    fudu
    Participant

    Hi, I’m trying to make a custom customer register form
    And to do so, i’ve to override this 2 file:

    CustomerBundle\Layout\DataProvider\FrontendCustomerUserRegistrationFormProvider.php
    and
    CustomerBundle\Form\Type\FrontendCustomerUserRegistrationType.php

    So i’ve put this code in config/config.yml and it work as expected:

    But i also need to override entity as well, so it will render a new column to the customer register form.

    I’ve notice that FrontendCustomerUserRegistrationType have this code:

    And so CustomerBundle\Resources\config\services.yml have that too:

    So i’ve override it using config/config.yml:

    But it doesn’t work, it throw an error

    The form’s view data is expected to be an instance of class My_Code\Bundle\CustomerBundle\Entity\CustomerUser, but is an instance of class Oro\Bundle\CustomerBundle\Entity\CustomerUser. You can avoid this error by setting the “data_class” option to null or by adding a view transformer that transforms an instance of class Oro\Bundle\CustomerBundle\Entity\CustomerUser to an instance of My_Code\Bundle\CustomerBundle\Entity\CustomerUser.

    I think it make the override of FrontendCustomerUserRegistrationType go wrong and failed.

    Here is my overrided FrontendCustomerUserRegistrationType.php:

    Oh, and i’ve also created success 2 column “test” and “test2” in table “oro_customer_user” using oro:migrations.

    Just ask when you need more file to check, thanks for helping :)

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #37670
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    To extend the form it’s easier to use form type extensions instead of extending the form type and overriding all the places where the original form type was used.

    Please check the documentation on it:
    https://symfony.com/doc/2.8/form/create_form_type_extension.html

    P.S. Symfony forms extending works in a different way, you should not use PHP extends functionality, but instead, use getParent method. But I highly recommend you to use form type extensions instead

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No