Getting access to unmapped form fields in twig (Symfony 2.3)

2.1k Views Asked by At

I have form with hidden unmapped field:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        ...
        $builder
            ...
            ...
            ->add(
                'geolocationBreadcrumbs',
                'hidden',
                array(
                    'required' => false,
                    'mapped' => false
                )
            );
    }

I want to get access to value of that field in TWIG via {{ form.vars.value.field_name }}

<div>{{ form.vars.value.geolocationBreadcrumbs }}</div>

But I have an error: Method "geolocationBreadcrumbs" for object "Site\UserBundle\Entity\User" does not exist in "%path_to_twig_template%"

Why does Symfony 2.3 try to find method for unmapped field in Entity Class and how I can to get access to unmapped filed value direclty from twig?

Thanks.

1

There are 1 best solutions below

2
On BEST ANSWER

You can access value of this field calling:

{{ form.geolocationBreadcrumbs.vars.value }}

Calling form.vars.value you get access to User entity and that's why Symfony2 returns exception.