Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not exactly sure that it will work with the collection, but it certainly works with a single form. Please try this idea.</p> <p>First make a form for your basic entity <code>ComplaintBase</code></p> <pre><code>class ComplaintForm extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $subscriber = new ComplaintSubscriber($builder); $builder-&gt;addEventSubscriber($subscriber); /* your fields */ } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'Acme\ConsultBundle\Entity\ComplaintBase', )); } } </code></pre> <p>Then in subscriber you can define additional fields based on submitted entity type.</p> <pre><code>class ComplaintSubscriber implements EventSubscriberInterface { private $factory; private $builder; public function __construct(FormBuilderInterface $builder) { $this-&gt;factory = $builder-&gt;getFormFactory(); $this-&gt;builder = $builder; } public static function getSubscribedEvents() { return array( FormEvents::PRE_SET_DATA =&gt; 'preSetData', ); } public function preSetData(FormEvent $event) { $data = $event-&gt;getData(); $form = $event-&gt;getForm(); if (null === $data) { return; } $class = get_class($data); if( $class === 'Acme\ConsultBundle\Entity\ComplaintDefault' ) { $this-&gt;processDefault($data, $form); } elseif( $class === 'Acme\ConsultBundle\Entity\ComplaintRosacea' ) { $this-&gt;processRosacea($data, $form); } elseif( $class === 'Acme\ConsultBundle\Entity\ComplaintBotox' ) { $this-&gt;processBotox($data, $form); } else { #NOP } } protected function processDefault(Entity\ComplaintDefault $node, FormInterface &amp;$form) { #NOP } protected function processRosacea(Entity\ComplaintRosacea $node, FormInterface &amp;$form) { $form-&gt;add($this-&gt;factory-&gt;createNamed('some_field', 'text')); } protected function processBotox(Entity\ComplaintBotox $node, FormInterface &amp;$form) { $form-&gt;add($this-&gt;factory-&gt;createNamed('other_field', 'text')); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload