1

When i try to create a new user, with or without role(s) selected i straight have this error :

Invalid state, originalRoles array is not set

Roles choices are added that way (Not modified, straight from vendor):

->add('realRoles', 'sonata_security_roles', array(
                    'label'    => 'form.label_roles',
                    'expanded' => true,
                    'multiple' => true,
                    'required' => false
                ))

And here the code that return the exception (straight from vendor, so probably not a good idea to fix the error here except if it is a real issue).

/**
 * {@inheritdoc}
 */
public function reverseTransform($selectedRoles)
{
    if ($this->originalRoles === null) {
        throw new \RuntimeException('Invalid state, originalRoles array is not set');
    }

    list($availableRoles, ) = $this->rolesBuilder->getRoles();

    $hiddenRoles = array_diff($this->originalRoles, $availableRoles);

    return array_merge($selectedRoles, $hiddenRoles);
}

Any solutions or hints?

UPDATE :

Issue moved to Github Sonata with some more information.

Brieuc
  • 3,994
  • 9
  • 37
  • 70

1 Answers1

1

Problem caused by redefining of constructor in entity extending from Sonata\UserBundle\Entity\BaseUser

To solve this problem, add parent::construct() in the child entity.

chalasr
  • 12,971
  • 4
  • 40
  • 82
  • This project was long ago but you might be right, in a more recent project i did care about the construct method and didn't face this issue again. – Brieuc Dec 10 '15 at 16:00