famas23
famas23

Reputation: 2280

Can't access to attributes of a custom form type

I just created tow custom childs of forms Type 'InformationsType' and 'TeamsType' related to another form 'TrainingsType' via embed form:

TrainingsType:

use AppBundle\Form\InformationsType;
use AppBundle\Form\TeamsType;
class TrainingsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('team', TeamsType::class)
        ->add('information', InformationsType::class);
    }

TeamsType:

class TeamsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('nameInstitue')->add('nameSpace')->add('webSpace')


                 ->add('members', CollectionType::class, [
                    'entry_type' => Team_membersType::class,
                    'allow_delete' => true,
                    'allow_add' => true,
                    'by_reference' => false,
            ]);

    }

InformationsType:

class InformationsType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('category', ChoiceType::class, array(
            'choices'  => array(
                'Formation' => 'Francais',
                'Certification' => 'Certification',
                'Tutoriel' => 'Tutoriel',
                'Conférence' => 'Conférence',
                'Atelier' => 'Atelier',
                'Webinar' => 'Webinar',
                'Meet-up' => 'Meet-up',

                ),
            ))->add('language', ChoiceType::class, array(
            'choices'  => array(
                'Francais' => 'Francais',
                'Anglais' => 'Anglais',

                ),
            ))->add('eventType', ChoiceType::class, array(
            'choices'  => array(
                'Permanant' => 'Permanant',
                'Session' => 'Session',

                ),
            ))->add('priceDescription')->add('title')->add('webAdress')->add('description')->add('priceRadio')->add('validationType')



            ->add('trainingPrice',ChoiceType::class, array(
                'choices'  => array('Gratuit'=>'Gratuit','Payant'=>'Payant','Abonnement'=>'Abonnement'),'multiple'=>false,'expanded'=>true))


            ->add('isCheckedPiece', CheckboxType::class, array(


                'required' => false,
                ));
    }

When i render the Trainings form via {{form(form)}} every thing works . But in my case i need to loop form.team.members, because it's a collections type form with add and delete options, but here

the problém that i can't access to team attribute ({{form(form.team)}}, it doesnt exist !!

i tried to dump(form) and i get this Formview object without any team attribute it's wired, because i got my form when i rendred via {{form(form)}}:

FormView {#365 ▼
  +vars: array:24 [▼
    "value" => Informations {#313 ▶}
    "attr" => []
    "form" => FormView {#365}
    "id" => "appbundle_informations"
    "name" => "appbundle_informations"
    "full_name" => "appbundle_informations"
    "disabled" => false
    "label" => null
    "label_format" => null
    "multipart" => false
    "block_prefixes" => array:3 [▶]
    "unique_block_prefix" => "_appbundle_informations"
    "translation_domain" => null
    "cache_key" => "_appbundle_informations_appbundle_informations"
    "errors" => FormErrorIterator {#555 ▶}
    "valid" => true
    "data" => Informations {#313 ▶}
    "required" => true
    "size" => null
    "label_attr" => []
    "compound" => true
    "method" => "POST"
    "action" => ""
    "submitted" => false
  ]
  +parent: null
  +children: array:12 [▼
    "category" => FormView {#610 ▶}
    "language" => FormView {#641 ▶}
    "eventType" => FormView {#659 ▶}
    "priceDescription" => FormView {#668 ▶}
    "title" => FormView {#670 ▶}
    "webAdress" => FormView {#672 ▶}
    "description" => FormView {#674 ▶}
    "priceRadio" => FormView {#676 ▶}
    "validationType" => FormView {#678 ▶}
    "trainingPrice" => FormView {#680 ▶}
    "isCheckedPiece" => FormView {#682 ▶}
    "_token" => FormView {#696 ▶}
  ]
  -rendered: false
  -methodRendered: false
}

Any help, any explanation !!

Upvotes: 0

Views: 68

Answers (1)

Strnm
Strnm

Reputation: 1016

I think what you want to use is

attribute(form, team)

See https://twig.symfony.com/doc/2.x/functions/attribute.html

EDIT:

Your dump looks like a dump of InformationsType and not TrainingsType, are you sure you're using the right form?

Upvotes: 1

Related Questions