mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
role field added to user form. Works with select or radio button, not with checkbox...
This commit is contained in:
parent
1453fdcd18
commit
3ebeda9840
@ -228,7 +228,7 @@ class User implements AdvancedUserInterface
|
||||
$roles = $this->roles;
|
||||
$roles[] = 'ROLE_USER';
|
||||
|
||||
return array_unique($roles);
|
||||
return $roles;
|
||||
}
|
||||
|
||||
public function getSalt(): ?string
|
||||
|
@ -19,6 +19,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
@ -59,6 +60,16 @@ class UserType extends AbstractType
|
||||
return $qb;
|
||||
},
|
||||
])
|
||||
->add('roles', ChoiceType::class, [
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'Roles',
|
||||
'choices' => [
|
||||
'Usager' => 'ROLE_USER',
|
||||
'Administrateur' => 'ROLE_ADMIN',
|
||||
],
|
||||
])
|
||||
->add('mainScope', EntityType::class, [
|
||||
'label' => 'Main scope',
|
||||
'required' => false,
|
||||
@ -94,6 +105,18 @@ class UserType extends AbstractType
|
||||
},
|
||||
]);
|
||||
|
||||
$builder->get('roles')
|
||||
->addModelTransformer(new CallbackTransformer(
|
||||
function ($rolesArray) {
|
||||
// transform the array to a string
|
||||
return count($rolesArray)? $rolesArray[0]: null;
|
||||
},
|
||||
function ($rolesString) {
|
||||
// transform the string back to an array
|
||||
return [$rolesString];
|
||||
}
|
||||
));
|
||||
|
||||
if ($options['is_creation']) {
|
||||
$builder->add('plainPassword', RepeatedType::class, [
|
||||
'mapped' => false,
|
||||
|
@ -22,19 +22,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
*/
|
||||
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var AuthorizationCheckerInterface
|
||||
*/
|
||||
protected $authorizationChecker;
|
||||
protected AuthorizationCheckerInterface $authorizationChecker;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
/**
|
||||
* SectionMenuBuilder constructor.
|
||||
*/
|
||||
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
|
||||
{
|
||||
$this->authorizationChecker = $authorizationChecker;
|
||||
|
Loading…
x
Reference in New Issue
Block a user