MessageAdmin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
c 0
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureListFields() 0 6 1
A configureShowFields() 0 6 1
A configureRoutes() 0 4 1
A configureFormFields() 0 6 1
A configureDatagridFilters() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ForumBundle\Admin;
6
7
use ProjetNormandie\ForumBundle\Form\Type\RichTextEditorType;
8
use Sonata\AdminBundle\Admin\AbstractAdmin;
9
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
10
use Sonata\AdminBundle\Route\RouteCollectionInterface;
11
use Sonata\AdminBundle\Show\ShowMapper;
12
use Sonata\AdminBundle\Form\FormMapper;
13
use Sonata\AdminBundle\Datagrid\ListMapper;
14
use Sonata\AdminBundle\Datagrid\DatagridMapper;
15
use Sonata\AdminBundle\Route\RouteCollection;
16
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter;
17
use Symfony\Component\Form\Extension\Core\Type\TextType;
18
19
/**
20
 * Administration manager for the Forum Bundle.
21
 */
22
class MessageAdmin extends AbstractAdmin
23
{
24
    protected $baseRouteName = 'pnf_admin_message';
25
26
    /**
27
     * @param RouteCollection $collection
28
     */
29
    protected function configureRoutes(RouteCollectionInterface $collection): void
30
    {
31
        $collection->remove('export')
32
            ->remove('create');
33
    }
34
35
    /**
36
     * @param FormMapper $form
37
     */
38
    protected function configureFormFields(FormMapper $form): void
39
    {
40
        $form->add('id', TextType::class, ['label' => 'label.id', 'attr' => ['readonly' => true]])
41
            ->add('message', RichTextEditorType::class, [
42
                    'label' => 'label.message',
43
                    'required' => true,
44
                  ]);
45
    }
46
47
    /**
48
     * @param DatagridMapper $filter
49
     */
50
    protected function configureDatagridFilters(DatagridMapper $filter): void
51
    {
52
        $filter
53
            ->add('id', null, ['label' => 'label.id'])
54
            ->add('topic', ModelFilter::class, [
55
                'label' => 'label.topic',
56
                'field_type' => ModelAutocompleteType::class,
57
                'field_options' => ['property' => 'libTopic'],
58
            ]);
59
    }
60
61
    /**
62
     * @param ListMapper $list
63
     */
64
    protected function configureListFields(ListMapper $list): void
65
    {
66
        $list->addIdentifier('id', null, ['label' => 'label.id'])
67
            ->add('message', null, ['label' => 'label.message'])
68
            ->add('user', null, ['label' => 'label.user'])
69
            ->add('_action', 'actions', ['actions' => ['show' => [], 'edit' => []]]);
70
    }
71
72
    /**
73
     * @param ShowMapper $show
74
     */
75
    protected function configureShowFields(ShowMapper $show): void
76
    {
77
        $show->add('id', null, ['label' => 'label.id'])
78
            ->add('topic', null, ['label' => 'label.topic'])
79
            ->add('user', null, ['label' => 'label.user'])
80
            ->add('message', null, ['label' => 'label.message', 'safe' => true]);
81
    }
82
}
83