title: How to map one class variable to two form fields in Symfony
body: <p>I wold like to use Symfony 2.8 to create a form for data class, e.g. <code>Task</code> as used in the <a href="http://symfony.com/doc/2.8/forms.html" rel="nofollow noreferrer">Symfony docs</a>.</p>
  
  <p>My <code>Task</code> class uses an integer field <code>flags</code> to store a collection different bool values. For example the value of <code>is completed</code> is stored as the first bit and <code>is urgent</code> as the second bit:</p>
  
  <ul>
  <li>Task is <strong>not</strong> completed and <strong>not</strong> urgent --> flags = 0</li>
  <li>Task is completed and <strong>not</strong> urgent --> flags = 1</li>
  <li>Task is <strong>not</strong> completed and urgent --> flags = 2 </li>
  <li>Task is completed and urgent --> flags = 3</li>
  <li>...</li>
  </ul>
  
  <p><strong>The problem:</strong> How can this single class field be mapped to two different form fields and back?</p>
  
  <pre><code>$builder
      // map first bit to checkbox
      -&gt;add('is_complete', CheckboxType::class, array(
              ...
          )
      )
      // map second bit to selection box "normal"/"urgent"
      -&gt;add('is_urgend', ChoiceType::class, array(
              ...
          )
      )
      ...
  </code></pre>
  
  <p>What is the correct solution to solve this? Can this be handled by a <strong>Data Transformers</strong>? As far as I know, a transformer can translate a field of one to type to another type, but not one field to two fields. Is that correct?</p>
  
  <p>The only solution I found so far, is to create a wrapper class <code>TaskWrapper</code> which does not use flags but offers different bool fields for the each flag value. This class could than be passed to the form instead of the original <code>Task</code> class. Once the form is submitted the returned wrapper object could than be manually translated back to a <code>Task</code> object. </p>
  
  <p>This would work, but it is not a clean solution. Is this the way to go or is there a better solution using Symfony tools? </p>