ForumAdmin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 32
dl 0
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureRoutes() 0 3 1
A configureShowFields() 0 10 1
A configureDatagridFilters() 0 7 1
A configureListFields() 0 8 1
A configureFormFields() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ForumBundle\Admin;
6
7
use ProjetNormandie\ForumBundle\ValueObject\ForumStatus;
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\CheckboxType;
16
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
17
use Symfony\Component\Form\Extension\Core\Type\TextType;
18
use ProjetNormandie\ForumBundle\Entity\Forum;
19
20
/**
21
 * Administration manager for the Forum Bundle.
22
 */
23
class ForumAdmin extends AbstractAdmin
24
{
25
    protected $baseRouteName = 'pnf_admin_forum';
26
27
    /**
28
     * @param RouteCollection $collection
29
     */
30
    protected function configureRoutes(RouteCollectionInterface $collection): void
31
    {
32
        $collection->remove('export');
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('libForum', TextType::class, ['label' => 'label.forum'])
42
            ->add('libForumFr', TextType::class, ['label' => 'label.forumFr'])
43
            ->add('category')
44
            ->add(
45
                'status',
46
                ChoiceType::class,
47
                [
48
                    'label' => 'label.status',
49
                    'choices' => ForumStatus::getStatusChoices(),
50
                ]
51
            )
52
            ->add('position', TextType::class, ['label' => 'label.position', 'required' => true]);
53
    }
54
55
    /**
56
     * @param DatagridMapper $filter
57
     */
58
    protected function configureDatagridFilters(DatagridMapper $filter): void
59
    {
60
        $filter
61
            ->add('id', null, ['label' => 'label.id'])
62
            ->add('category', null, ['label' => 'label.category'])
63
            ->add('libForum', null, ['label' => 'label.forum'])
64
            ->add('status', null, ['label' => 'label.status']);
65
    }
66
67
    /**
68
     * @param ListMapper $list
69
     */
70
    protected function configureListFields(ListMapper $list): void
71
    {
72
        $list->addIdentifier('id', null, ['label' => 'label.id'])
73
            ->add('category', null, ['label' => 'label.category'])
74
            ->add('libForum', null, ['label' => 'label.forum'])
75
            ->add('status', null, ['label' => 'label.status'])
76
            ->add('position', null, ['label' => 'label.position'])
77
            ->add('_action', 'actions', ['actions' => ['show' => [], 'edit' => []]]);
78
    }
79
80
    /**
81
     * @param ShowMapper $show
82
     */
83
    protected function configureShowFields(ShowMapper $show): void
84
    {
85
        $show->add('id', null, ['label' => 'label.id'])
86
            ->add('category', null, ['label' => 'label.category'])
87
            ->add('libForum', null, ['label' => 'label.forum'])
88
            ->add('libForumFr', null, ['label' => 'label.forumFr'])
89
            ->add('position', null, ['label' => 'label.position'])
90
            ->add('nbTopic', null, ['label' => 'label.nbTopic'])
91
            ->add('nbMessage', null, ['label' => 'label.nbMessage'])
92
            ->add('lastMessage', null, ['label' => 'label.lastMessage']);
93
    }
94
}
95