/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setRequestHandler($this->requestHandler); if ($options['json_format']) { $builder->addEventSubscriber(new JsonExtensionListener()); } }
/** * Create the Form definition. * * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setRequestHandler(new JsonApiRequestHandler()); $builder->add('id', HiddenType::class)->add('name', TextType::class)->add('manufacturer', TextType::class)->add('model', TextType::class)->add('instrumentType', EntityType::class, ['class' => 'InstrumentBundle:InstrumentType', 'choice_label' => 'name']); // Add specification $formModifier = function (FormInterface $form, \InstrumentBundle\Entity\InstrumentType $instrumentType = null) { $prefix = null === $instrumentType ? 'Abstract' : $instrumentType->getPrefix(); $form->add('specification', 'InstrumentBundle\\Form\\Type\\Specification\\' . $prefix . 'SpecificationType'); }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) { // Get Instrument Entity $data = $event->getData(); $formModifier($event->getForm(), $data->getInstrumentType()); }); $builder->get('instrumentType')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) { // Get Instrument Entity $instrumentType = $event->getForm()->getData(); $formModifier($event->getForm()->getParent(), $instrumentType); }); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber($this->listener); $builder->setRequestHandler($this->requestHandler); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setRequestHandler($this->requestHandler); }