Completed
Push — SF4 ( 4699a1...dd087e )
by Laurent
08:29
created

UserController::updateUserEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * UserController Controller of User entity.
5
 *
6
 * PHP Version 7
7
 *
8
 * @author    Quétier Laurent <[email protected]>
9
 * @copyright 2018 Dev-Int GLSR
10
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
11
 *
12
 * @version GIT: $Id$
13
 *
14
 * @link https://github.com/Dev-Int/glsr
15
 */
16
17
namespace App\Controller;
18
19
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController as BaseAdminController;
20
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
21
22
/**
23
 * User Controller override EasyAdminBundle::AdminController
24
 *
25
 * @category Controller
26
 */
27
class UserController extends BaseAdminController
28
{
29
    public function createUserEntityFormBuilder($entity, $view)
30
    {
31
        $hierarchy = $this->getParameter('security.role_hierarchy.roles');
32
33
        // transform the role hierarchy in a single unique list
34
        $roles = array();
35
        array_walk_recursive($hierarchy, function ($role) use (&$roles) {
36
            $roles[$role] = $role;
37
        });
38
39
        $formBuilder = $this->createEntityFormBuilder($entity, $view);
40
        $formBuilder->
41
            add('roles', ChoiceType::class, [
42
                'expanded' => true,
43
                'multiple' => true,
44
                'placeholder' => 'Choice a role',
45
                'choices' => $roles,
46
            ]);
47
48
        return $formBuilder;
49
    }
50
}
51