如何在不与实体相关的情况下将表单集合嵌入表单中?

时间:2018-12-20 13:53:41

标签: php doctrine symfony-forms

我的整个问题是我有一个表单,我希望嵌入几种表单集合,我有一个外部实体,它来自一个实体和其他具有自己实体的表单,但事实与它们无关彼此,并且我希望当我将整个表单及其子表单一起提交时,每个子表单都保留自己的实体验证,这就是我到目前为止所拥有的:

我尝试在子表单解析器中使用继承,但是当我将这些表单嵌入外部表单中时,它希望它在实体中具有这些字段,而不是我的情况。

// this is the outer form where I want to render its subforms
class DocumentoType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder

            ->add('tipodoc', EntityType::class, array(
                'class' => 'CGR\DocumentoBundle\Entity\TipoDoc',
                'placeholder' => 'Please choose',
                'required' => true,
                'query_builder' => function (EntityRepository $er) {
                   return $er->createQueryBuilder('e')
                   ->orderBy('e.nombre', 'ASC');
                },
                'label' => '* Tipo de Documento',
                'choice_label' => 'nombre',
                'placeholder'=>'Seleccione...',
                'mapped' => false,
            ))

           // this is the collection of a form I wish to render
            ->add('foo', CollectionType::class, array(
    // each entry in the array will be an "email" field
    'entry_type' => ReservaPtoCtaType::class,
    // these options are passed to each "email" type
    'entry_options' => array(
        'attr' => array('class' => 'email-box'),
    ),))  ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CGR\DocumentoBundle\Entity\Documento'
        ));
    }}

        // this is the subform that I want to embedd inside the other form
  $builder
            //->add('correlativo')
            ->add('asunto', TextareaType::class, array(
              'required' => true,
            ))
                 // lots of other fields
    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CGR\DocumentoBundle\Entity\ReservaPtoCta',
            'user' => null
        ));
    }

我设法通过继承嵌入了子表单,但是我说它们没有映射,这不是我想要的,我想要的是将子表单嵌入外部表单(表单+子表单)中,而不必在事务上相互关联实体。

0 个答案:

没有答案