HistoryAdmin::configureFormFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 51
ccs 15
cts 15
cp 1
crap 1
rs 9.069
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Admin;
4
5
use App\Entity\History;
6
use FOS\CKEditorBundle\Form\Type\CKEditorType;
7
use Sonata\AdminBundle\Admin\AbstractAdmin;
8
use Sonata\AdminBundle\Datagrid\ListMapper;
9
use Sonata\AdminBundle\Datagrid\DatagridMapper;
10
use Sonata\AdminBundle\Form\FormMapper;
11
use Sonata\AdminBundle\Form\Type\ModelListType;
12
use Sonata\Form\Type\CollectionType;
13
use Sonata\Form\Type\DateTimePickerType;
14
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
15
16
class HistoryAdmin extends AbstractAdmin
17
{
18
    protected $baseRouteName = 'App\Entity\History';
19
    protected $baseRoutePattern = 'History';
20
    protected $datagridValues = [
21
        '_sort_order' => 'ASC',
22
        '_sort_by' => 'name',
23
    ];
24
25
    /**
26
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
27
     *
28
     * @return void
29
     */
30 2
    protected function configureFormFields(FormMapper $formMapper)
31
    {
32
        $formMapper
33 2
            ->add('title')
34 2
            ->add('type', ChoiceType::class, [
35 2
                'choices'  => History::getTypes()
36
            ])
37 2
            ->add('dateTime', DateTimePickerType::class,
38
                [
39 2
                    'label' => 'History_Date',
40
                    'widget' => 'single_text',
41
                    'format' => 'yyyy'
42
                ]
43
            )
44 2
            ->add('text', CKEditorType::class,
45
                [
46
                    'attr' => [
47 2
                            'class' => 'wysihtml5',
48
                            'style' => 'height:300px',
49
                    ],
50
                ]
51
            )
52 2
            ->add('mainPicture', ModelListType::class,
53
                [
54 2
                    'required' => false,
55
                    'btn_list' => false,
56
                ], [
57
                    'link_parameters' => [
58 2
                        'context' => 'history',
59
                        'provider' => 'sonata.media.provider.image',
60
                    ],
61
                ]
62
            )
63 2
            ->add('galleryHasMedia', CollectionType::class,
64
                [
65 2
                    'required' => false,
66
                    'label' => 'Gallery'
67
                ], [
68 2
                    'edit' => 'inline',
69
                    'inline' => 'table',
70
                    'sortable'  => 'position',
71
                    'targetEntity' => 'App\Entity\GalleryHasMedia',
72
                    'admin_code' => 'sonata.media.admin.gallery_has_media',
73
                    'link_parameters' => [
74
                        'context'  => 'history',
75
                        'provider' => 'sonata.media.provider.image',
76
                    ],
77
                ]
78
            )
79
        ;
80 2
    }
81
    /**
82
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
83
     *
84
     * @return void
85
     */
86 2 View Code Duplication
    protected function configureListFields(ListMapper $listMapper)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $listMapper
89 2
            ->add('mainPicture', 'string', ['template' => 'bundles/SonataAdmin/thumbnail.html.twig'])
90 2
            ->add('year', null, ['label' => 'History_Date'])
91 2
            ->addIdentifier('title')
92 2
            ->add('type')
93 2
            ->add('_action', 'actions',
94
                [
95
                    'actions' => [
96 2
                        'edit' => [],
97
                        'delete' => [],
98
                    ],
99
                ]
100
            )
101
        ;
102 2
    }
103
104
    /**
105
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
106
     *
107
     * @return void
108
     */
109 2
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
110
    {
111
        $datagridMapper
112 2
            ->add('title')
113 2
            ->add('dateTime');
114 2
    }
115
}
116