PartnerAdmin::configureListFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\PartnerBundle\Admin;
6
7
use ProjetNormandie\PartnerBundle\ValueObject\PartnerStatus;
8
use Sonata\AdminBundle\Admin\AbstractAdmin;
9
use Sonata\AdminBundle\Route\RouteCollectionInterface;
10
use Sonata\AdminBundle\Show\ShowMapper;
11
use Sonata\AdminBundle\Form\FormMapper;
12
use Sonata\AdminBundle\Datagrid\ListMapper;
13
use Sonata\AdminBundle\Datagrid\DatagridMapper;
14
use Sonata\AdminBundle\Route\RouteCollection;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\Form\Extension\Core\Type\EmailType;
17
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
18
use Symfony\Component\Form\Extension\Core\Type\TextType;
19
20
class PartnerAdmin extends AbstractAdmin
21
{
22
    protected $baseRouteName = 'pnp_partner_admin';
23
24
    /**
25
     * @param RouteCollection $collection
26
     */
27
    protected function configureRoutes(RouteCollectionInterface $collection): void
28
    {
29
        $collection->remove('export');
30
    }
31
32
    /**
33
     * @param FormMapper $form
34
     */
35
    protected function configureFormFields(FormMapper $form): void
36
    {
37
        $form->add('name', TextType::class, ['label' => 'label.name'])
38
            ->add(
39
                'status',
40
                ChoiceType::class,
41
                [
42
                    'label' => 'label.status',
43
                    'choices' => PartnerStatus::getStatusChoices(),
44
                ]
45
            )
46
            ->add('url', TextType::class, ['label' => 'label.url'])
47
            ->add('contact', EmailType::class, ['label' => 'label.contact', 'required' => false])
48
            ->add(
49
                'description',
50
                TextareaType::class,
51
                ['label' => 'label.description', 'required' => false, 'attr' => ['rows' => 10]]
52
            )
53
            ->add(
54
                'comment',
55
                TextareaType::class,
56
                ['label' => 'label.comment', 'required' => false, 'attr' => ['rows' => 10]]
57
            );
58
    }
59
60
    /**
61
     * @param DatagridMapper $filter
62
     */
63
    protected function configureDatagridFilters(DatagridMapper $filter): void
64
    {
65
        $filter
66
            ->add('name', null, ['label' => 'label.name'])
67
            ->add('status', null, ['label' => 'label.status']);
68
    }
69
70
    /**
71
     * @param ListMapper $list
72
     */
73
    protected function configureListFields(ListMapper $list): void
74
    {
75
        $list->addIdentifier('id', null, ['label' => 'label.id'])
76
            ->add('name', null, ['label' => 'label.name'])
77
            ->add('status', null, ['label' => 'label.status'])
78
            ->add('url', 'text', ['label' => 'label.url'])
79
            ->add('contact', 'text', ['label' => 'label.contact'])
80
            ->add('_action', 'actions', ['actions' => ['show' => [], 'edit' => []]]);
81
    }
82
83
    /**
84
     * @param ShowMapper $show
85
     */
86
    protected function configureShowFields(ShowMapper $show): void
87
    {
88
        $show->add('id', null, ['label' => 'label.id'])
89
            ->add('name', null, ['label' => 'label.name'])
90
            ->add('status', null, ['label' => 'label.status'])
91
            ->add('url', null, ['label' => 'label.url'])
92
            ->add('contact', null, ['label' => 'label.contact'])
93
            ->add('description', null, ['label' => 'label.description'])
94
            ->add('comment', null, ['label' => 'label.comment']);
95
    }
96
}
97