FOSUserBundle simple User roles editing form
<p>Trying to create a form that will allow me to select User roles but it's not working.</p>

<p>Here is my User class:</p>

<pre><code>namespace TestBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="TestBundle\Repository\UserRepository")
 */
class User extends BaseUser
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this-&gt;id;
    }
}
</code></pre>

<p>And here is my form definition:</p>

<pre><code>class ChangeUserRolesType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $permissions = array(
             'ROLE_USER'        =&gt; 'First role',
             'ROLE_CONSULT'     =&gt; 'Second role',
             'ROLE_SUPER_ADMIN' =&gt; 'Third role'
         );

        $builder
            -&gt;add('username', EntityType::class, array(
                'class' =&gt; 'TestBundle:User',
                'choice_label' =&gt; 'username'
            ))
            -&gt;add(
                'roles',
                ChoiceType::class,
                array(
                    'label'   =&gt; 'Roles',
                    'choices' =&gt; $permissions,
                    'multiple' =&gt; true,
                    'expanded' =&gt; true
                )
            )
            -&gt;add(
                'save',
                SubmitType::class
            );

    }


    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver-&gt;setDefaults(array(
            'data_class' =&gt; 'TestBundle\Entity\User',
        ));
    }

}
</code></pre>

<p>This is my controller action that creates the form:</p>

<pre><code>/**
 * @Route("/")
 */
public function indexAction()
{
    $users = $this-&gt;getDoctrine()-&gt;getRepository('TestBundle:User')-&gt;findAll();

    $user = $this-&gt;getDoctrine()-&gt;getRepository('TestBundle:User')-&gt;findOneBy(array('username' =&gt; 'liviu'));

    $editUserForm = $this-&gt;createForm('TestBundle\Form\ChangeUserRolesType', $user);


    return $this-&gt;render('TestBundle:Default:index.html.twig', array(
        'users' =&gt; $users,
        'form' =&gt; $editUserForm-&gt;createView()
    ));
}
</code></pre>

<p>But I am getting this error:</p>

<blockquote>
  <p>Warning: Missing argument 1 for FOS\UserBundle\Model\User::hasRole(),
  called in
  /home/liviu/apps/app1/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php
  on line 416 and defined 500 Internal Server Error -
  ContextErrorException</p>
</blockquote>

<p>does anyone know what's going on ? I am on Symfony 3.0.*</p>