PlatformAdmin::configureListFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\IgdbBundle\Admin;
6
7
use Sonata\AdminBundle\Admin\AbstractAdmin;
8
use Sonata\AdminBundle\Datagrid\DatagridMapper;
9
use Sonata\AdminBundle\Datagrid\ListMapper;
10
use Sonata\AdminBundle\Form\FormMapper;
11
use Sonata\AdminBundle\Route\RouteCollectionInterface;
12
use Sonata\AdminBundle\Show\ShowMapper;
13
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter;
14
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
15
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
16
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
17
use Symfony\Component\Form\Extension\Core\Type\TextType;
18
use VideoGamesRecords\IgdbBundle\Entity\Platform;
19
use VideoGamesRecords\IgdbBundle\Entity\PlatformLogo;
20
use VideoGamesRecords\IgdbBundle\Entity\PlatformType;
21
22
/**
23
 * @extends AbstractAdmin<Platform>
24
 */
25
final class PlatformAdmin extends AbstractAdmin
26
{
27
    protected function configureRoutes(RouteCollectionInterface $collection): void
28
    {
29
        $collection
30
            ->remove('create')
31
            ->remove('edit')
32
            ->remove('delete')
33
            ->remove('export');
34
    }
35
36
    protected function configureFormFields(FormMapper $form): void
37
    {
38
        // Read-only admin - no form fields needed as data comes from IGDB API
39
    }
40
41
    protected function configureDatagridFilters(DatagridMapper $filter): void
42
    {
43
        $filter
44
            ->add('id', null, ['label' => 'field.id'])
45
            ->add('name', null, ['label' => 'field.platform.name'])
46
            ->add('abbreviation', null, ['label' => 'field.platform.abbreviation'])
47
            ->add('generation', null, ['label' => 'field.platform.generation'])
48
            ->add('slug', null, ['label' => 'field.slug'])
49
            ->add('platformType', ModelFilter::class, [
50
                'field_type' => EntityType::class,
51
                'field_options' => [
52
                    'class' => PlatformType::class,
53
                    'choice_label' => 'name',
54
                ],
55
                'label' => 'field.platform.platform_type',
56
            ]);
57
    }
58
59
    protected function configureListFields(ListMapper $list): void
60
    {
61
        $list
62
            ->add('id', null, ['label' => 'field.id'])
63
            ->add('name', null, ['label' => 'field.platform.name'])
64
            ->add('abbreviation', null, ['label' => 'field.platform.abbreviation'])
65
            ->add('generation', null, ['label' => 'field.platform.generation'])
66
            ->add('platformType.name', null, ['label' => 'field.platform.platform_type'])
67
            ->add('createdAt', null, ['label' => 'field.created_at'])
68
            ->add('updatedAt', null, ['label' => 'field.updated_at'])
69
            ->add(ListMapper::NAME_ACTIONS, null, [
70
                'actions' => [
71
                    'show' => ['template' => null],
72
                ],
73
            ]);
74
    }
75
76
    protected function configureShowFields(ShowMapper $show): void
77
    {
78
        $show
79
            ->add('id', null, ['label' => 'field.id'])
80
            ->add('name', null, ['label' => 'field.platform.name'])
81
            ->add('abbreviation', null, ['label' => 'field.platform.abbreviation'])
82
            ->add('alternativeName', null, ['label' => 'field.platform.alternative_name'])
83
            ->add('generation', null, ['label' => 'field.platform.generation'])
84
            ->add('slug', null, ['label' => 'field.slug'])
85
            ->add('summary', null, ['label' => 'field.platform.summary'])
86
            ->add('url', null, ['label' => 'field.url'])
87
            ->add('checksum', null, ['label' => 'field.checksum'])
88
            ->add('platformType.name', null, ['label' => 'field.platform.platform_type'])
89
            ->add('platformLogo.imageId', null, ['label' => 'field.platform.platform_logo'])
90
            ->add('createdAt', null, ['label' => 'field.created_at'])
91
            ->add('updatedAt', null, ['label' => 'field.updated_at']);
92
    }
93
}
94