Passed
Pull Request — master (#494)
by Andrew
04:59
created

SponsorAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 46
dl 0
loc 80
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBatchActions() 0 2 1
A configureFormFields() 0 49 2
A configureListFields() 0 12 1
1
<?php
2
3
namespace Stfalcon\Bundle\SponsorBundle\Admin;
4
5
use Sonata\AdminBundle\Form\FormMapper;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Stfalcon\Bundle\SponsorBundle\Entity\Sponsor;
8
use Stfalcon\Bundle\EventBundle\Admin\AbstractClass\AbstractTranslateAdmin;
9
10
/**
11
 * SponsorAdmin Class.
12
 */
13
class SponsorAdmin extends AbstractTranslateAdmin
14
{
15
    /**
16
     * @return array|void
17
     */
18
    public function getBatchActions()
19
    {
20
    }
21
22
    /**
23
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
24
     */
25
    protected function configureListFields(ListMapper $listMapper)
26
    {
27
        $listMapper
28
            ->addIdentifier('name', null, ['label' => 'Название'])
29
            ->add('site', null, ['label' => 'Сайт'])
30
            ->add('about', null, ['label' => 'Описание'])
31
            ->add('sortOrder', null, ['label' => 'Номер сортировки'])
32
            ->add('_action', 'actions', [
33
                'label' => 'Действие',
34
                'actions' => [
35
                    'edit' => [],
36
                    'delete' => [],
37
                ],
38
            ]);
39
    }
40
41
    /**
42
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
43
     */
44
    protected function configureFormFields(FormMapper $formMapper)
45
    {
46
        /** @var Sponsor $subject */
47
        $subject = $this->getSubject();
48
        $localsRequiredService = $this->getConfigurationPool()->getContainer()->get('application_default.sonata.locales.required');
49
        $localOptionsAllFalse = $localsRequiredService->getLocalsRequiredArray(false);
50
        $formMapper
51
            ->with('Переводы')
52
            ->add('translations', 'a2lix_translations_gedmo', [
53
                'label' => 'Переводы',
54
                'translatable_class' => $this->getClass(),
55
                'fields' => [
56
                    'about' => [
57
                        'label' => 'Описание',
58
                        'locale_options' => $localOptionsAllFalse,
59
                    ],
60
                ],
61
            ])
62
            ->end()
63
            ->with('Общие')
64
                ->add('name')
65
                ->add('site', null, ['label' => 'Сайт'])
66
                ->add(
67
                    'file',
68
                    'file',
69
                    [
70
                        'label' => 'Логотип',
71
                        'required' => false,
72
                        'data_class' => 'Symfony\Component\HttpFoundation\File\File',
73
                        'property_path' => 'file',
74
                        'help' => $subject->getLogo() ? $subject->getLogo() : '',
75
                    ]
76
                )
77
                ->add('sortOrder', null, ['attr' => ['min' => 1], 'label' => 'Номер сортировки'])
78
            ->end()
79
            ->with('События')
80
                ->add(
81
                    'sponsorEvents',
82
                    'sonata_type_collection',
83
                    [
84
                        'label' => 'Спонсируемые события',
85
                        'by_reference' => false,
86
                    ],
87
                    [
88
                        'edit' => 'inline',
89
                        'inline' => 'table',
90
                    ]
91
                )
92
            ->end();
93
    }
94
}
95