I have a user edit form where I would like to administer the roles assigned to a user.
Currently I have a multi-select list, but I have no way of populating it with
For to symfony 2.3:
getParameter('security.role_hierarchy.roles');
$this->roles = $this->flatArray($roles);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'choices' => $this->roles
));
}
public function getParent()
{
return 'choice';
}
public function getName()
{
return 'permission_choice';
}
private function flatArray(array $data)
{
$result = array();
foreach ($data as $key => $value) {
if (substr($key, 0, 4) === 'ROLE') {
$result[$key] = $key;
}
if (is_array($value)) {
$tmpresult = $this->flatArray($value);
if (count($tmpresult) > 0) {
$result = array_merge($result, $tmpresult);
}
} else {
$result[$value] = $value;
}
}
return array_unique($result);
}
}