Passed
Push — develop ( 4a6bb0...113a9b )
by BENARD
02:13
created

CommentAdmin::generateBaseRouteName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ArticleBundle\Admin;
6
7
use ProjetNormandie\ArticleBundle\Form\Type\RichTextEditorType;
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 Sonata\DoctrineORMAdminBundle\Filter\ModelFilter;
16
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
17
use Symfony\Component\Form\Extension\Core\Type\TextType;
18
use Sonata\AdminBundle\Form\Type\ModelListType;
19
20
class CommentAdmin extends AbstractAdmin
21
{
22
    protected function generateBaseRouteName(bool $isChildAdmin = false): string
23
    {
24
        return 'pna_comment_admin';
25
    }
26
27
    /**
28
     * @param RouteCollection $collection
29
     */
30
    protected function configureRoutes(RouteCollectionInterface $collection): void
31
    {
32
        $collection
33
            ->remove('create')
34
            ->remove('export');
35
    }
36
37
    /**
38
     * @param FormMapper $form
39
     */
40
    protected function configureFormFields(FormMapper $form): void
41
    {
42
        $form
43
            ->add('id', TextType::class, ['label' => 'comment.form.id', 'attr' => ['readonly' => true]])
44
            ->add('user', ModelListType::class, [
45
                'btn_add' => false,
46
                'btn_list' => false,
47
                'btn_edit' => false,
48
                'btn_delete' => false,
49
                'btn_catalogue' => false,
50
                'label' => 'comment.form.user',
51
             ])
52
            ->add('article', ModelListType::class, [
53
                'btn_add' => false,
54
                'btn_list' => false,
55
                'btn_edit' => false,
56
                'btn_delete' => false,
57
                'btn_catalogue' => false,
58
                'label' => 'comment.form.article',
59
            ])
60
            ->add('content', RichTextEditorType::class, [
61
                'label' => 'comment.form.content',
62
                'required' => true,
63
            ]);
64
    }
65
66
    /**
67
     * @param DatagridMapper $filter
68
     */
69
    protected function configureDatagridFilters(DatagridMapper $filter): void
70
    {
71
        $filter
72
            ->add('article.translations.title', null, ['label' => 'comment.filter.article'])
73
            ->add('user', ModelFilter::class, [
74
                'label' => 'comment.filter.user',
75
                'field_type' => ModelAutocompleteType::class,
76
                'field_options' => ['property' => 'username'],
77
            ])
78
        ;
79
    }
80
81
    /**
82
     * @param ListMapper $list
83
     */
84
    protected function configureListFields(ListMapper $list): void
85
    {
86
        $list->addIdentifier('id', null, ['label' => 'comment.list.id'])
87
            ->add('article', null, ['label' => 'comment.list.article'])
88
            ->add('user', null, ['label' => 'comment.list.user'])
89
            ->add('createdAt', null, ['label' => 'comment.list.created_at'])
90
            ->add('_action', 'actions', [
91
                'actions' => [
92
                    'show' => [],
93
                    'edit' => [],
94
                ]
95
            ]);
96
    }
97
98
    /**
99
     * @param ShowMapper $show
100
     */
101
    protected function configureShowFields(ShowMapper $show): void
102
    {
103
        $show
104
            ->add('id', null, ['label' => 'comment.show.id'])
105
            ->add('user', null, ['label' => 'comment.show.user'])
106
            ->add('article', null, ['label' => 'comment.show.article'])
107
            ->add('content', null, ['label' => 'comment.show.content', 'safe' => true]);
108
    }
109
}
110