MenuAdmin::configureFormFields()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
rs 8.8571
cc 2
eloc 19
nc 2
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\MenuBundle\Controller\Admin\CRUD;
4
5
use Sonata\AdminBundle\Admin\Admin;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Sonata\AdminBundle\Form\FormMapper;
8
use Sonata\AdminBundle\Route\RouteCollection;
9
10
class MenuAdmin extends Admin
11
{
12
    public function createQuery($context = 'list')
13
    {
14
        $query = parent::createQuery($context);
15
        $query->addOrderBy($query->getRootAlias().'.locale', 'ASC');
16
17
        return $query;
18
    }
19
20
    protected function configureRoutes(RouteCollection $collection)
21
    {
22
        $collection->remove('create');
23
        $collection->remove('delete');
24
        $collection->add('item', $this->getRouterIdParameter().'/item');
25
    }
26
27
    protected function configureFormFields(FormMapper $formMapper)
28
    {
29
        $container = $this->getConfigurationPool()->getContainer();
30
        $locales = $container->getParameter('lunetics_locale.allowed_locales');
31
        $locales = array_combine($locales, $locales);
32
33
        $formMapper
34
            ->add('name', null, [
35
                'label'    => 'Label',
36
                'required' => true,
37
            ]);
38
39
        $security = $this->getSecurityHandler();
40
        $isAuthorized = $security->isGranted($this, 'ROLE_SUPER_ADMIN');
41
42
        if ($isAuthorized) {
43
            $formMapper
44
                ->add('locale', 'choice', [
45
                    'label'    => 'Langue',
46
                    'choices'  => $locales,
47
                    'required' => true,
48
                ])
49
                ->add('machineName', null, [
50
                    'label'    => 'Nom de la machine',
51
                    'required' => true,
52
                ]);
53
        }
54
    }
55
56
    protected function configureListFields(ListMapper $listMapper)
57
    {
58
        $listMapper
59
            ->add('locale', null, [
60
                'label'    => 'Langue',
61
                'required' => true,
62
            ])
63
            ->add('name', null, [
64
                'label'    => 'Label',
65
                'required' => true,
66
            ])
67
            ->add('_action', 'actions', [
68
                'actions' => [
69
                    'item' => [
70
                        'template' => 'AlpixelMenuBundle:CRUD:list__action_item.html.twig',
71
                    ],
72
                ],
73
            ]);
74
    }
75
}
76