简体   繁体   中英

Symfony 2, Sonata User Bundle : Invalid state, originalRoles array is not set

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM