Completed
Pull Request — master (#4)
by Alexis
02:30
created

MenuAdmin::createQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
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
56
    protected function configureListFields(ListMapper $listMapper)
57
    {
58
        $listMapper
59
            ->add('machineName', null, [
60
                'label'    => 'Nom de la machine',
61
                'required' => true,
62
            ])
63
            ->add('name', null, [
64
                'label'    => 'Label',
65
                'required' => true,
66
            ])
67
            ->add('locale', null, [
68
                'label'    => 'Langue',
69
                'required' => true,
70
            ])
71
            ->add('_action', 'actions', [
72
                'actions' => [
73
                    'item' => [
74
                        'template' => 'AlpixelMenuBundle:CRUD:list__action_item.html.twig',
75
                    ],
76
                    'edit' => [],
77
                ],
78
            ]);
79
    }
80
}
81