Completed
Push — master ( 4ddf1e...018837 )
by Benjamin
02:28
created

MenuAdmin::configureRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
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->add('item', $this->getRouterIdParameter().'/item');
24
    }
25
26
    protected function configureFormFields(FormMapper $formMapper)
27
    {
28
        $container = $this->getConfigurationPool()->getContainer();
29
        $locales = $container->getParameter('lunetics_locale.allowed_locales');
30
        $locales = array_combine($locales, $locales);
31
32
        $formMapper
33
            ->add('name', null, [
34
                'label'    => 'Label',
35
                'required' => true,
36
            ]);
37
38
        $security = $this->getSecurityHandler();
39
        $isAuthorized = $security->isGranted($this, 'ROLE_SUPER_ADMIN');
40
41
        if ($isAuthorized) {
42
            $formMapper
43
                ->add('locale', 'choice', [
44
                    'label'    => 'Langue',
45
                    'choices'  => $locales,
46
                    'required' => true,
47
                ])
48
                ->add('machineName', null, [
49
                    'label'    => 'Nom de la machine',
50
                    'required' => true,
51
                ]);
52
        }
53
    }
54
55
    protected function configureListFields(ListMapper $listMapper)
56
    {
57
        $listMapper
58
            ->add('locale', null, [
59
                'label'    => 'Langue',
60
                'required' => true,
61
            ])
62
            ->add('name', null, [
63
                'label'    => 'Label',
64
                'required' => true,
65
            ])
66
            ->add('_action', 'actions', [
67
                'actions' => [
68
                    'item' => [
69
                        'template' => 'AlpixelMenuBundle:CRUD:list__action_item.html.twig',
70
                    ],
71
                    'add' => [
72
                        'template' => 'AlpixelMenuBundle:CRUD:add__action_item.html.twig',
73
                    ],
74
                ],
75
            ]);
76
    }
77
}
78