ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 7 replies, has 2 voices, and was last updated by Yevhen Shyshkin Yevhen Shyshkin 2 years, 5 months ago.

  • Creator
    Topic
  • #6427

    Ximousse
    Participant

    Hello all,

    I’m trying to implement a small app with OroPlatform and I have the following problem:
    I have an entity ‘Person’ which is linked through a OneToMany relationship to an entity ‘SocialNetwork’, here are the annotations:

    I tried to do the same as the Contact entity and Address entity of the OroCRM bundle but whenever I try to post a form to create a new entity Contact without filling the social network fields I have the following error:

    whereas it’s not a problem to leave the address fields empty in OroCRM while creating a new contact.
    In a “classical” bundle I would normally set the default argument of addSocialNetwork to null but it doesn’t work (and it’s not used in OroCRM).
    Am I missing something ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #6433
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    Hello, Ximousse.

    Probably, you should look at Oro\Bundle\FormBundle\Form\EventListener\CollectionTypeSubscriber::postSubmit – it checks collection for empty elements and remove them. Collection form type must be oro_collection or you can add this subscriber manually to your collection. Also to support this functionality your entity must implement interface Oro\Bundle\FormBundle\Entity\EmptyItem.

    #6437

    Ximousse
    Participant

    Thank you Yevhen for your hint,
    However I do have in my collection type:

    and my Entity extends an abstract class with:

    I’ll dig in the CollectionTypeSubscriber to try to find why it’s nor working for me.

    #6514

    Ximousse
    Participant

    Ok, nevermind it was a simple cache problem so the EmptyItem works fine (and is extremely useful). Thanks!

    #6515

    Ximousse
    Participant

    Ok I spoke too fast. I still have the problem:
    In CollectionTypeSubscriber the following condition:

    never gets fired because $item is null if I don’t fill at least one field of the entity in the OneToMany relationship.

    #6516
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    Then you should check when and why null added to your collection – f.e. you can add breakpoint to add method. Probable reason – incorrect configuration of form type that should return only objects.

    #6639

    Ximousse
    Participant

    I had the time to dig a bit into this, and I’m still a bit confused:
    the problem I have comes from this: https://github.com/symfony/symfony/issues/9375
    in vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/Type/FormType.php

    thus, if I remove the required: false for my “SocialNetworkCollection” from my FormType I don’t have the problem anymore.
    What bothers me is that the field is now marked as “required” (even though I can now leave it empty) and in OroCRM/ContactBundle/Form/Type/ContactType all the collections linked to the contact entity have the required option set to false.

    #6654
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    Thank you for sharing your results!

    If you still need to make field not required, you can pass custom “empty_data” option as empty instance of handled object.

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

You must be logged in to reply to this topic.