OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – Programming Questions Adding fields to existing entities (Account)

This topic contains 9 replies, has 3 voices, and was last updated by  Rodolfo 9 years, 5 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #24871

    Jaimy
    Participant

    Hi Fellow Oro’ers,

    I’ve seen everybody is having a struggle with adding fields to existing entities, and I’m experiencing the exact same. I’m trying to add a field to the Account entity, ofcourse after reading the other topics and https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/EntityExtendBundle/README.md, I’ve added a migration script for this field.

    The migration script works perfectly, and I can see (by using ExtendScope::OWNER_CUSTOM) the field is nicely added to the Additional Information tab. The thing is that you can only use the “target fields” from the entity I want to include in the Account. In my case this is the Oro User, I can select the username but I would like to use the “oro_user_select” instead of the options from a specific field (i.e. username, firstname or a different field from Oro User).

    I’ve tried to use ExtendScope::OWNER_SYSTEM and have tried to add the form fields manually and this works out, but only when you’re adding the ‘mapped => false’ option to the form field you want to add (since the fields are not actually mapped by the Account entity and it will throw an error if you do not specify this option).

    At this point I’m stuck at the above since I do not see how I can make use of the “oro_user_select” form field, and saving it’s value on the Account entity. Do I need to override the Formhandler as well? If so how do I get the values back to the form, like it was a mapped field of the Account entity?

    I’m looking forward to some of your ideas on this matter.

    Kind Regards,

    Jaimy Casteleijn

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #24872

    ignat
    Participant

    Hello, Jaimy!

    As you can see in current released version of OroPlatform you cannot specify form type of custom entity field as it’s hard-coded (https://github.com/orocrm/platform/blob/1.3/src/Oro/Bundle/EntityBundle/Form/Type/CustomEntityType.php#L33).

    But if you really need to customize the type for your field you can try to use a mechanism of Symfony’s form extending. I think it should work as a temporary solution at least until a corresponding option will be introduced. Try to use a form listener or a form extension. I assume that you will be able to manipulate your specific form type and change field that you want dynamically.

    A possible scenario of form listener/form extension will be:
    1) Subscribe for appropriate event of form type of your entity (Account entity, form type – orocrm_account);
    2) Find child in this form that represents your custom field (user field, form type – oro_entity_select);
    3) Replace this child with a new one that matches your requirements, for example add field with “oro_user_select” type and the same name.

    Thanks,
    Ignat

    #24873

    Jaimy
    Participant

    Hi Ignat!

    Thanks for the quick responds! I would love to see that feature coming into a future release since I think this is going to happen more often :). You’re doing an absolutely fantastic job on the platform and CRM, keep up the good work!

    Kind Regards,

    Jaimy Casteleijn

    #24874

    Jaimy
    Participant

    Hi Ignat,

    This “temporary” solution works perfectly! I’ll an example code in a bit to my github account (and drop a link at twitter and here in the forum) so others don’t have to struggle with the problem :).

    Kind Regards,

    Jaimy Casteleijn

    #24875

    Jaimy
    Participant

    Hi Ignat,

    Added the example code to my github profile (https://github.com/24198/ExtendAccountBundle).
    Thanks again!

    Kind Regards,

    Jaimy Casteleijn

    #24876

    ignat
    Participant

    Hi Jaimy,

    Thank you for sharing this. I will drop a message here when normal solution will be available. I guess it would be in 1.4.1.

    Thanks,
    Ignat

    #24877

    Jaimy
    Participant

    Hi Ignat,

    No problem :). I’ll look forward to a “normal” solution ;).

    Kind Regards,

    Jaimy Casteleijn

    #24878

    ignat
    Participant

    Hi Jaimy,

    JFYI, in 1.4.1 a new approach for customized rendering of custom fields on forms and views was introduced.
    It’s described in this docs:
    https://github.com/orocrm/platform/blob/1.4.1/src/Oro/Bundle/EntityExtendBundle/README.md#custom-form-type-and-options
    https://github.com/orocrm/platform/blob/1.4.1/src/Oro/Bundle/EntityExtendBundle/README.md#extend-fields-view

    Thanks,
    Ignat

    #24879

    Jaimy
    Participant

    Hi Ignat,

    Thanks for the heads up! We will create an new demo bundle for the new approach ;), w’ll also change the code as soon as we update to 1.4.1.

    Kind Regards,

    Jaimy Casteleijn

    #24880

    Rodolfo
    Participant

    Hey guys.. can I extend a bundle marked as “NO EXTENDABLE”?

Viewing 9 replies - 1 through 9 (of 9 total)

The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.

Back to top