title: Symfony data transformer after $form->isValid()
body: <p>I ran into a trouble of understanding how exactly data is processed in <a href="http://symfony.com/doc/current/cookbook/form/data_transformers.html" rel="nofollow">DataTransformers</a> of <strong>Symfony</strong>.</p>
  
  <p>I have a just a password form. Just one field. This field belongs to the User entity which has to constraints defined in <code>.yml</code> file.</p>
  
  <pre><code>Software\Bundle\Entity\User:
      password:
          - NotBlank: ~
          - Length:
              min: 6
              max: 155
  </code></pre>
  
  <p>The validation works fine, as supposed to. The problem arise when password must be encoded automatically from the field. So, </p>
  
  <pre><code>    $builder-&gt;add('password', 'password', [
          'label' =&gt; 'word.password'
      ]);
  
      $builder-&gt;get('password')
          -&gt;addModelTransformer(new EncodePasswordTransformer());
  </code></pre>
  
  <p>And the transformer itself:</p>
  
  <pre><code>class EncodePasswordTransformer implements DataTransformerInterface
  {
      public function transform($value)
      {
          return $value;
      }
  
      public function reverseTransform($value)
      {
          // encode password
          return PasswordHash::createHash($value);
      }
  }
  </code></pre>
  
  <p>So here's what's happening:</p>
  
  <p>The form should contain 6 to 155 characters but <code>$form-&gt;isValid()</code> is always true, because the <code>PasswordHash::createHash($value)</code> encodes the password to 32 characters. What I was expecting is:</p>
  
  <p>Form validates raw password, if more than 6 chars then go to <code>$form-&gt;isValid()</code> true and then encode the password after it's validated.</p>
  
  <p>I know I can just encode the password manually while the form is valid without using <code>DataTransformer</code> but I was hoping for a bit more elegant way.</p>
  
  <p>Am I wrong?</p>