Passed
Push — develop ( 527962...2758c7 )
by BENARD
09:34
created

ArticleAdmin::setSecurity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ArticleBundle\Admin;
6
7
use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
8
use ProjetNormandie\ArticleBundle\ValueObject\ArticleStatus;
9
use Sonata\AdminBundle\Admin\AbstractAdmin;
10
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
11
use Sonata\AdminBundle\Show\ShowMapper;
12
use Sonata\AdminBundle\Form\FormMapper;
13
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
14
use Sonata\AdminBundle\Datagrid\ListMapper;
15
use Sonata\AdminBundle\Datagrid\DatagridMapper;
16
use Sonata\AdminBundle\Route\RouteCollectionInterface;
17
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter;
18
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
19
use Symfony\Component\Form\Extension\Core\Type\TextType;
20
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
21
use FOS\CKEditorBundle\Form\Type\CKEditorType;
22
23
class ArticleAdmin extends AbstractAdmin
24
{
25
    protected $baseRouteName = 'pna_article_admin';
26
27
    /**
28
     * @param RouteCollectionInterface $collection
29
     */
30
    protected function configureRoutes(RouteCollectionInterface $collection): void
31
    {
32
        $collection->remove('export');
33
    }
34
35
    protected function configureDefaultSortValues(array &$sortValues): void
36
    {
37
        $sortValues['_page'] = 1;
38
        $sortValues['_sort_order'] = 'DESC';
39
        $sortValues['_sort_by'] = 'id';
40
    }
41
42
    /**
43
     * @param ProxyQueryInterface $query
44
     * @return ProxyQueryInterface
45
     */
46
    protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
47
    {
48
        $query = parent::configureQuery($query);
49
        $query->leftJoin($query->getRootAliases()[0]  . '.translations', 't')
0 ignored issues
show
Bug introduced by
The method leftJoin() does not exist on Sonata\AdminBundle\Datagrid\ProxyQueryInterface. It seems like you code against a sub-type of Sonata\AdminBundle\Datagrid\ProxyQueryInterface such as Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        $query->/** @scrutinizer ignore-call */ 
50
                leftJoin($query->getRootAliases()[0]  . '.translations', 't')
Loading history...
Bug introduced by
The method getRootAliases() does not exist on Sonata\AdminBundle\Datagrid\ProxyQueryInterface. It seems like you code against a sub-type of Sonata\AdminBundle\Datagrid\ProxyQueryInterface such as Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        $query->leftJoin($query->/** @scrutinizer ignore-call */ getRootAliases()[0]  . '.translations', 't')
Loading history...
50
            ->addSelect('t');
51
        return $query;
52
    }
53
54
55
    /**
56
     * @param FormMapper $form
57
     */
58
    protected function configureFormFields(FormMapper $form): void
59
    {
60
        $form
61
            ->add('id', TextType::class, ['label' => 'label.id', 'attr' => ['readonly' => true]])
62
            ->add(
63
                'status',
64
                ChoiceType::class,
65
                [
66
                    'label' => 'label.status',
67
                    'choices' => ArticleStatus::getStatusChoices(),
68
                ]
69
            )
70
            ->add('publishedAt', DateTimeType::class, [
71
                'label' => 'label.publishedAt',
72
                'required' => false,
73
                'years' => range(2004, date('Y'))
74
            ])
75
            ->add('translations', TranslationsType::class, [
76
                'required' => true,
77
                'fields' => [
78
                    'title' => [
79
                        'field_type' => TextType::class,
80
                        'label' => 'label.title',
81
                    ],
82
                    'text' => [
83
                        'field_type' => CKEditorType::class,
84
                        'label' => 'label.text',
85
                    ]
86
                ]
87
            ]);
88
    }
89
90
    /**
91
     * @param DatagridMapper $filter
92
     */
93
    protected function configureDatagridFilters(DatagridMapper $filter): void
94
    {
95
        $filter
96
            ->add(
97
                'author',
98
                ModelFilter::class,
99
                [
100
                    'label' => 'label.author',
101
                    'field_type' => ModelAutocompleteType::class,
102
                    'field_options' => ['property' => 'username'],
103
                ]
104
            )
105
            ->add('translations.title', null, ['label' => 'label.title'])
106
            ->add('status', null, ['label' => 'label.status']);
107
    }
108
109
    /**
110
     * @param ListMapper $list
111
     */
112
    protected function configureListFields(ListMapper $list): void
113
    {
114
        $list->addIdentifier('id', null, ['label' => 'label.id'])
115
            ->add('getDefaultTitle', null, ['label' => 'label.title'])
116
            ->add('author', null, ['label' => 'label.author'])
117
            ->add(
118
                'status',
119
                'choice',
120
                [
121
                    'label' => 'label.status',
122
                    'editable' => false,
123
                    'choices' => ArticleStatus::getStatusChoices(),
124
                ]
125
            )
126
            ->add('createdAt', null, ['label' => 'label.createdAt'])
127
            ->add('published_at', 'datetime', ['label' => 'label.publishedAt'])
128
            ->add('_action', 'actions', [
129
                'actions' => [
130
                    'show' => [],
131
                    'edit' => [],
132
                    'groups' => [
133
                        'template' => '@ProjetNormandieArticle/Admin/article_comments_link.html.twig'
134
                    ],
135
                ]
136
            ]);
137
    }
138
139
    /**
140
     * @param ShowMapper $show
141
     */
142
    protected function configureShowFields(ShowMapper $show): void
143
    {
144
        $show
145
            ->add('id', null, ['label' => 'label.id'])
146
            ->add('status', null, ['label' => 'label.status'])
147
            ->add('getDefaultTitle', null, ['label' => 'label.title'])
148
            ->add('getDefaultText', null, ['label' => 'label.text', 'safe' => true]);
149
    }
150
}
151