title: Generating forms with Symfony 2.8 throws a Twig_Error_Runtime
body: <p>Since the last LTS version of Symfony was released few days ago (30.11.2015) I started playing with it. Unfortunately I can't generate a CRUD with write actions with the same code that works fine in Symfony 2.7.7.</p>
  
  <p>First I create a new Symfony project using the <code>bash</code> under Linux Mint 17.2:</p>
  
  <pre><code>symfony new tasks lts
  </code></pre>
  
  <p>The new directory <code>tasks</code> gets created with a new Symfony 2.8.0 project inside.</p>
  
  <p>After adapting the database credentials in <code>app/config/parameters.yml</code> I create the database:</p>
  
  <pre><code>app/console doctrine:database:create
  </code></pre>
  
  <p>and generate a new bundle:</p>
  
  <pre><code>app/console generate:bundle --namespace=Acme/TasksBundle --format=yml
  </code></pre>
  
  <p>Then I create a new directory <code>src/Acme/TasksBundle/Resources/config/doctrine</code> and place two files for my models inside. These are:</p>
  
  <p>Task.orm.yml</p>
  
  <pre><code>Acme\TasksBundle\Entity\Task:
      type: entity
      repositoryClass: Acme\TasksBundle\Repository\TaskRepository
      table: task
      id:
          id:
              type: integer
              generator: { strategy : AUTO }
      fields:
          description:
              type: text
      manyToMany:
          tags:
              targetEntity: Tag
              inversedBy: tasks
              cascade: [ "persist" ]
              joinTable:
                  name: task_tag
                  joinColumns:
                      task_id:
                          referencedColumnName: id
                  inverseJoinColumns:
                      tag_id:
                          referencedColumnName: id
  </code></pre>
  
  <p>Tag.orm.yml</p>
  
  <pre><code>Acme\TasksBundle\Entity\Tag:
      type: entity
      repositoryClass: Acme\TasksBundle\Repository\TagRepository
      table: tag
      id:
          id:
              type: integer
              generator: { strategy : AUTO }
      fields:
          name:
              type: string
              length: 50
      manyToMany:
          tasks:
              targetEntity: Task
              mappedBy: tags
  </code></pre>
  
  <p>The database schema should like this:</p>
  
  <pre><code>+----------------+     +--------------+
  | task           |     | task_tag     |     +---------+
  +----------------+     +--------------+     | tag     |
  |   id           |&lt;---&gt;|   task_id    |     +---------+
  |   description  |     |   tag_id     |&lt;---&gt;|   id    |
  +----------------+     +--------------+     |   name  |
                                              +---------+
  </code></pre>
  
  <p>Now I can generate the entities:</p>
  
  <pre><code>app/console generate:doctrine:entities AcmeTasksBundle
  </code></pre>
  
  <p>This works fine, so the database can be updated:</p>
  
  <pre><code>app/console doctrine:schema:update --force
  </code></pre>
  
  <p>Everything ok till now. The tables are in the database. Now I want to generate CRUD with write actions:</p>
  
  <pre><code>app/console generate:doctrine:crud --entity=AcmeTasksBundle:Task --with-write --format=yml
  </code></pre>
  
  <p>After confirming few questions it generates the CRUD and prints out:</p>
  
  <pre><code>Generating the CRUD code: OK
  </code></pre>
  
  <p>and afterwards throws this error:</p>
  
  <pre><code>[Twig_Error_Runtime]                                                                                    
  Key "tags" for array with keys "id, description" does not exist in "form/FormType.php.twig" at line 29
  </code></pre>
  
  <p>The controller gets created, but not the form.</p>
  
  <p>Generating the CRUD without write options works fine. The very same code works flawlessly with Symfony 2.7.7.</p>
  
  <p>I checked the differences in the file <code>form/FormType.php.twig</code> between the versions and here are the relevant parts:</p>
  
  <p>Symfony 2.7.7<br>
  <code>vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton/form/FormType.php.twig</code></p>
  
  <pre><code>{%- if fields|length &gt; 0 %}
  /**
   * @param FormBuilderInterface $builder
   * @param array $options
   */
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
      {%- for field in fields %}
  
          -&gt;add('{{ field }}')
      {%- endfor %}
  
      ;
  }
  {% endif %}
  </code></pre>
  
  <p>Symfony 2.8.0<br>
  <code>vendor/sensio/generator-bundle/Resources/skeleton/form/FormType.php.twig</code></p>
  
  <pre><code>{%- if fields|length &gt; 0 %}
  /**
   * @param FormBuilderInterface $builder
   * @param array $options
   */
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
  
      {%- for field in fields -%}
          {%- if fields_mapping[field]['type'] in ['date', 'time', 'datetime'] %}
  
          -&gt;add('{{ field }}', '{{ fields_mapping[field]['type'] }}')
  
          {%- else %}
  
          -&gt;add('{{ field }}')
  
          {%- endif -%}
      {%- endfor %}
  
      ;
  }
  {% endif %}
  </code></pre>
  
  <p>As I see the if condition in the for loop is the place where the error occurs. (I assume that the expression <code>fields_mapping[field]['type']</code> causes the problem since the many to many field (<code>tag</code>) has no attribute <code>type</code>.)</p>
  
  <p>What I am doing wrong? How can I solve this problem? Thank you very much for your help.</p>
  
  <p>EDIT:
  The same problem occurs with Symfony 3.0.0. The file <code>form/FormType.php.twig</code> has been changed since version 2.8.</p>