GameAdmin::configureShowFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 20
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 25
rs 9.6
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\Game;
19
use VideoGamesRecords\IgdbBundle\Entity\Genre;
20
use VideoGamesRecords\IgdbBundle\Entity\Platform;
21
22
/**
23
 * @extends AbstractAdmin<Game>
24
 */
25
final class GameAdmin 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.game.name'])
46
            ->add('slug', null, ['label' => 'field.slug'])
47
            ->add('firstReleaseDate', null, ['label' => 'field.game.first_release_date'])
48
            ->add('versionParent', ModelFilter::class, [
49
                'field_type' => EntityType::class,
50
                'field_options' => [
51
                    'class' => Game::class,
52
                    'choice_label' => 'name',
53
                ],
54
                'label' => 'field.game.version_parent',
55
            ])
56
            ->add('genres', ModelFilter::class, [
57
                'field_type' => EntityType::class,
58
                'field_options' => [
59
                    'class' => Genre::class,
60
                    'choice_label' => 'name',
61
                    'multiple' => true,
62
                ],
63
                'label' => 'field.game.genres',
64
            ])
65
            ->add('platforms', ModelFilter::class, [
66
                'field_type' => EntityType::class,
67
                'field_options' => [
68
                    'class' => Platform::class,
69
                    'choice_label' => 'name',
70
                    'multiple' => true,
71
                ],
72
                'label' => 'field.game.platforms',
73
            ]);
74
    }
75
76
    protected function configureListFields(ListMapper $list): void
77
    {
78
        $list
79
            ->add('id', null, ['label' => 'field.id'])
80
            ->add('name', null, ['label' => 'field.game.name'])
81
            ->add('slug', null, ['label' => 'field.slug'])
82
            ->add('firstReleaseDate', null, [
83
                'template' => '@VideoGamesRecordsIgdb/Admin/list_unix_timestamp.html.twig',
84
                'label' => 'field.game.first_release_date',
85
            ])
86
            ->add('versionParent.name', null, ['label' => 'field.game.version_parent'])
87
            ->add('createdAt', null, ['label' => 'field.created_at'])
88
            ->add('updatedAt', null, ['label' => 'field.updated_at'])
89
            ->add(ListMapper::NAME_ACTIONS, null, [
90
                'actions' => [
91
                    'show' => ['template' => null],
92
                ],
93
            ]);
94
    }
95
96
    protected function configureShowFields(ShowMapper $show): void
97
    {
98
        $show
99
            ->add('id', null, ['label' => 'field.id'])
100
            ->add('name', null, ['label' => 'field.game.name'])
101
            ->add('slug', null, ['label' => 'field.slug'])
102
            ->add('storyline', null, ['label' => 'field.game.storyline'])
103
            ->add('summary', null, ['label' => 'field.game.summary'])
104
            ->add('url', null, ['label' => 'field.url'])
105
            ->add('checksum', null, ['label' => 'field.checksum'])
106
            ->add('firstReleaseDate', null, [
107
                'template' => '@VideoGamesRecordsIgdb/Admin/show_unix_timestamp.html.twig',
108
                'label' => 'field.game.first_release_date',
109
            ])
110
            ->add('versionParent.name', null, ['label' => 'field.game.version_parent'])
111
            ->add('genres', null, [
112
                'template' => '@VideoGamesRecordsIgdb/Admin/show_collection.html.twig',
113
                'label' => 'field.game.genres',
114
            ])
115
            ->add('platforms', null, [
116
                'template' => '@VideoGamesRecordsIgdb/Admin/show_collection.html.twig',
117
                'label' => 'field.game.platforms',
118
            ])
119
            ->add('createdAt', null, ['label' => 'field.created_at'])
120
            ->add('updatedAt', null, ['label' => 'field.updated_at']);
121
    }
122
}
123