Completed
Pull Request — master (#6)
by Benjamin
12:56
created

MenuAdmin::configureFormFields()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 29
rs 8.8571
cc 2
eloc 19
nc 2
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
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
<<<<<<< HEAD
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_SL, expecting ']'
Loading history...
77
=======
78
                    'edit' => [],
79
>>>>>>> master
80
                ],
81
            ]);
82
    }
83
}
84