mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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 = $this->roles;
|
||||||
$roles[] = 'ROLE_USER';
|
$roles[] = 'ROLE_USER';
|
||||||
|
|
||||||
return array_unique($roles);
|
return $roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSalt(): ?string
|
public function getSalt(): ?string
|
||||||
|
@ -19,6 +19,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
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\ChoiceType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||||
@ -59,6 +60,16 @@ class UserType extends AbstractType
|
|||||||
return $qb;
|
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, [
|
->add('mainScope', EntityType::class, [
|
||||||
'label' => 'Main scope',
|
'label' => 'Main scope',
|
||||||
'required' => false,
|
'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']) {
|
if ($options['is_creation']) {
|
||||||
$builder->add('plainPassword', RepeatedType::class, [
|
$builder->add('plainPassword', RepeatedType::class, [
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
|
@ -22,19 +22,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
*/
|
*/
|
||||||
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
||||||
{
|
{
|
||||||
/**
|
protected AuthorizationCheckerInterface $authorizationChecker;
|
||||||
* @var AuthorizationCheckerInterface
|
|
||||||
*/
|
|
||||||
protected $authorizationChecker;
|
|
||||||
|
|
||||||
/**
|
protected TranslatorInterface $translator;
|
||||||
* @var TranslatorInterface
|
|
||||||
*/
|
|
||||||
protected $translator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SectionMenuBuilder constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
|
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->authorizationChecker = $authorizationChecker;
|
$this->authorizationChecker = $authorizationChecker;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user