This topic contains 1 reply, has 2 voices, and was last updated by Mike Kudelya 7 years, 1 month ago.
- Topic
Hello,
I have created a form type, which looks something like that:
12345678910111213141516171819$builder->add('description',TextareaType::class,['label' => 'description','required' => true,])->add('client',EntityType::class,['empty_value' => '','label' => 'client','required' => true,'class' => Client::class,]);Such a form without ‘client’ element (which is of Symfony\Bridge\Doctrine\Form\Type\EntityType) works fine both in browser and via API. But I cannot use EntityType via API, because, I as understand, it is not registered as API form type (we want to use JSON API, provided by OroApiBundle).
Later I have found that ORO platform has its own Oro\Bundle\ApiBundle\Form\Type\EntityType, which I can use via API (but it does not work from browser) if I configure it like this:12345678910111213$metadata = new AssociationMetadata();$metadata->setAssociationType('manyToOne');$metadata->setTargetClassName(Client::class);$builder->add('client','oro_api_entity',['required' => true,'data_class' => Client::class,'metadata' => $metadata,]);I would like to reuse my form type to create new entities both in browser and in external apps via API. So far, I am thinking about registering this form as two services and use correct entity type, based on the service type:
12345678910111213form.type.my_form:class: FCQN\To\MyFormTypearguments:- 'web'tags:- { name: form.type }form.type.my_form_api:class: FCQN\To\MyFormType // the same form type classarguments:- 'api'tags:- { name: oro.api.form.type, alias: my_form_api }This solution would work for us, but I just wanted to get some feedback from ORO team if this is good practice, or if there is a better way to reuse custom form type in API.
Thank you.
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.