title: Adding customised validation rules to SonataUserBundle
body: <p>I have installed SonataUserBundle according to the docs and it all works fine. Except that I cannot add custom validation rules.</p>
  
  <p>My understanding is that the new rules should be added to a new Validation Group and then config.yml is updated to tell SonataUserBundle (or FosUserBundle) to add the new rules to the validation sequence.</p>
  
  <p>I have tried this, in various ways, but the new rules just don't seem to be picked up at all...</p>
  
  <p>Here's the configuration I'm using...</p>
  
  <p>(For the sake of this example, I'm just trying to adding a NotNull constraint to a new foo field. In reality I would like to see this much work and then add more validation rules.)</p>
  
  <p>I have added the foo field to <code>Application\Sonata\UserBundle\Resources\config\doctrine\User.orm.xml</code> and that all works fine, adding the foo field to the <code>User.php</code> class.</p>
  
  <pre><code># in Application\Sonata\UserBundle\Resources\config\doctrine\User.orm.xml
  ...
  &lt;field name="foo" type="string" length="100" nullable="true" /&gt;
  ...
  </code></pre>
  
  <p>In User.php we have the property with its getters and setters:</p>
  
  <pre><code>// In Application\Sonata\UserBundle\Entity\User.php
  // ...
  /**
   * @var string
   */
  private $foo;
  
  /**
   * Set foo
   *
   * @param string $foo
   * @return User
   */
  public function setFoo($foo)
  {
      $this-&gt;foo = $foo;
  
      return $this;
  }
  
  /**
   * Get foo
   *
   * @return string 
   */
  public function getFoo()
  {
      return $this-&gt;foo;
  }
  // ...
  </code></pre>
  
  <p>I have then added the new validation rule to my project's existing validation.yml file:</p>
  
  <pre><code>Application\Sonata\UserBundle\Entity\User:
      properties:
          foo:
              - NotNull: { groups: [CustomGroup] }
  </code></pre>
  
  <p>(Note that I have also tried creating a validation.yml and validation.xml file in Application\Sonata\UserBundle\Resources\config but that didn't seem to make any difference.)</p>
  
  <p>In config.yml I tell SonataUserBundle to use my new CustomGroup for validation:</p>
  
  <pre><code>sonata_user:
      # ...
      profile:
          form:
              validation_groups:  [CustomGroup, Profile, Default]
  </code></pre>
  
  <p>(Note that I have also tried adding the validation group at the fos_user level (<code>fos_user.profile.form.validation_groups: [CustomGroup, Profile, Default]</code>) and adding in <code>sonata_user.profile.register.form.validation_groups: [CustomGroup, Registration, Default]</code>, but to no avail.)</p>
  
  <p>And, for completeness, here's the field added to UserAdmin.php:</p>
  
  <pre><code>// In Application\Sonata\UserBundle\Admin\UserAdmin.php
  protected function configureFormFields(FormMapper $formMapper)
  {
      $formMapper
          -&gt;with('General')
              // ...
              -&gt;add('foo',        null, array('required' =&gt; false))
          -&gt;end()
      ;
  }
  </code></pre>
  
  <p>So... what have I missed? Is the UserAdmin form not the same as the 'profile' form? (Although I have also tried updating the registration form settings) Or do I set the validation rules somewhere else?</p>
  
  <p>Hopefully I've just missed something small!</p>
  
  <p>Thanks in advance,</p>
  
  <p>C</p>