title: Access form.vars.value in Symfony subform using Twig
body: <p>I am working on a Symfony 2.7 WebApp and I would like to use a custom Form Widget for one of the entites. The Widgets needs to access the <code>form.vars.value</code>. This works fine as long as the Widget is uses within the main form. But when using the Widget in a subform, <code>form.vars.value</code> is empty.</p>
  
  <p>The classes used within the form:</p>
  
  <pre><code>class AdressBookEntry { 
      // The main phone number of this contact: Type PhoneNumber
      protected $mainPhoneNumber;
      //...getter and setter for mainPhoneNumber
  
      // An array of Addresses
      protected $addresses;
      //...getter and setter for addresses
  
      ...
  }
  
  class Address { 
      // The phone number of this address: Type PhoneNumber
      protected $phoneNumber;
      //...getter and setter for phoneNumber
  
      ...
  }
  
  class PhoneNumber {
      ...
  }
  </code></pre>
  
  <p>The custom Form Types for theses classes:</p>
  
  <pre><code>// Custom FormType for AddressBookEntries
  class AdressBookEntryType extends AbstractType {
      ...
  
      public function buildForm(FormBuilderInterface $builder, array $options) {  
          // Type 'phone_number_edit' is registered in services.yml
          $builder
              -&gt;add('mainPhoneNumber', 'phone_number_edit', array(
                  'label' =&gt; '...',
                  ... 
              ))  
  
              -&gt;add('addresses', 'collection', array(
                  'label' =&gt; '...',
                  ... 
              ));
      }
  }
  
  
  // Custom FormType for Address
  class AddressType extends AbstractType {
      ...
  
      public function buildForm(FormBuilderInterface $builder, array $options) {  
          $builder
              -&gt;add('mainPhoneNumber', 'phone_number_edit', array(
                  'label' =&gt; '...',
                  ... 
              ))  
  
              ...;
      }
  }
  </code></pre>
  
  <p>The custom Widget for the PhoneNumberEdit</p>
  
  <pre><code>{% block phone_number_edit_widget %}
      ...
      {{ dump(form.vars.value) }}
      ...
  </code></pre>
  
  <p>The PhoneNumberEdit for the main form (representing the <code>AddressBookEntry</code>) works fine. The <code>dump</code> statement shows the content of the assigned <code>PhoneNumber</code> object.</p>
  
  <p>Within the Subform of the <code>addresses</code> collection however, the <code>form.vars.value</code> variable is empty. The dump shows just <code>""</code>.</p>
  
  <p>So, how do I access <code>form.vars.value</code> within the subform? How can the widget recognize wether it is being uses within the main form or a subform? </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Some additional information as asked in the comments:</p>
  
  <p>@Jeet: As described before the dump shows an empty value/string: <code>""</code></p>
  
  <p>@DOZ: This is the Twig code:</p>
  
  <pre><code>{{ form_start(form) }}
      {{ form_errors(form) }}         
      {{ form_row(form.name) }}
  
      {{ form_widget(mainPhoneNumber) }}
  
      &lt;ul data-prototype"{{ _self.addressItem(form.addresses.vars.prototype)|e('html_attr') }}" &gt;
          {% for address in form.addresses %}
              {{ _self.addressItem(address) }}
          {% endfor %}
      &lt;/u&gt;
  
      ...
  {{ form_end(form) }}
  
  {% macro addressItem(address) %}
      &lt;li&gt;
          {{ form_widget(address.phoneNumber) }}
          ...
      &lt;/li&gt;
  {% endmacro %}  
  </code></pre>