|
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 ProjetNormandie\ArticleBundle\Form\Type\RichTextEditorType; |
|
10
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
11
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
|
12
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
|
13
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
14
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; |
|
15
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
16
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
17
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
|
18
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter; |
|
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
21
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; |
|
22
|
|
|
use FOS\CKEditorBundle\Form\Type\CKEditorType; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class ArticleAdmin extends AbstractAdmin |
|
25
|
|
|
{ |
|
26
|
|
|
protected function generateBaseRouteName(bool $isChildAdmin = false): string |
|
27
|
|
|
{ |
|
28
|
|
|
return 'pna_article_admin'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
|
32
|
|
|
{ |
|
33
|
|
|
$collection->remove('export'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function configureDefaultSortValues(array &$sortValues): void |
|
37
|
|
|
{ |
|
38
|
|
|
$sortValues['_page'] = 1; |
|
39
|
|
|
$sortValues['_sort_order'] = 'DESC'; |
|
40
|
|
|
$sortValues['_sort_by'] = 'id'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
|
44
|
|
|
{ |
|
45
|
|
|
$query = parent::configureQuery($query); |
|
46
|
|
|
$query->leftJoin($query->getRootAliases()[0] . '.translations', 't') |
|
|
|
|
|
|
47
|
|
|
->addSelect('t'); |
|
48
|
|
|
return $query; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function configureFormFields(FormMapper $form): void |
|
52
|
|
|
{ |
|
53
|
|
|
$form |
|
54
|
|
|
->add('id', TextType::class, [ |
|
55
|
|
|
'label' => 'article.form.id', |
|
56
|
|
|
'attr' => ['readonly' => true], |
|
57
|
|
|
'required' => false, |
|
58
|
|
|
'disabled' => true |
|
59
|
|
|
]) |
|
60
|
|
|
->add( |
|
61
|
|
|
'status', |
|
62
|
|
|
ChoiceType::class, |
|
63
|
|
|
[ |
|
64
|
|
|
'label' => 'article.form.status', |
|
65
|
|
|
'choices' => ArticleStatus::getStatusChoices(), |
|
66
|
|
|
] |
|
67
|
|
|
) |
|
68
|
|
|
->add('publishedAt', DateTimeType::class, [ |
|
69
|
|
|
'label' => 'article.form.published_at', |
|
70
|
|
|
'required' => false, |
|
71
|
|
|
'years' => range(2004, date('Y')) |
|
72
|
|
|
]) |
|
73
|
|
|
->add('translations', TranslationsType::class, [ |
|
74
|
|
|
'label' => false, |
|
75
|
|
|
'fields' => [ |
|
76
|
|
|
'title' => [ |
|
77
|
|
|
'field_type' => TextType::class, |
|
78
|
|
|
'label' => 'Title', |
|
79
|
|
|
], |
|
80
|
|
|
'content' => [ |
|
81
|
|
|
'field_type' => RichTextEditorType::class, |
|
82
|
|
|
'label' => 'Content', |
|
83
|
|
|
] |
|
84
|
|
|
] |
|
85
|
|
|
]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
|
89
|
|
|
{ |
|
90
|
|
|
$filter |
|
91
|
|
|
->add( |
|
92
|
|
|
'author', |
|
93
|
|
|
ModelFilter::class, |
|
94
|
|
|
[ |
|
95
|
|
|
'label' => 'article.filter.author', |
|
96
|
|
|
'field_type' => ModelAutocompleteType::class, |
|
97
|
|
|
'field_options' => ['property' => 'username'], |
|
98
|
|
|
] |
|
99
|
|
|
) |
|
100
|
|
|
->add('translations.title', null, ['label' => 'article.filter.title']) |
|
101
|
|
|
->add('status', null, ['label' => 'article.filter.status']); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
protected function configureListFields(ListMapper $list): void |
|
105
|
|
|
{ |
|
106
|
|
|
$list->addIdentifier('id', null, ['label' => 'article.list.id']) |
|
107
|
|
|
->add('getDefaultTitle', null, ['label' => 'article.list.title']) |
|
108
|
|
|
->add('author', null, ['label' => 'article.list.author']) |
|
109
|
|
|
->add( |
|
110
|
|
|
'status', |
|
111
|
|
|
'choice', |
|
112
|
|
|
[ |
|
113
|
|
|
'label' => 'article.list.status', |
|
114
|
|
|
'editable' => false, |
|
115
|
|
|
'choices' => ArticleStatus::getStatusChoices(), |
|
116
|
|
|
] |
|
117
|
|
|
) |
|
118
|
|
|
->add('createdAt', null, ['label' => 'article.list.created_at']) |
|
119
|
|
|
->add('publishedAt', 'datetime', ['label' => 'article.list.published_at']) |
|
120
|
|
|
->add('_action', 'actions', [ |
|
121
|
|
|
'actions' => [ |
|
122
|
|
|
'show' => [], |
|
123
|
|
|
'edit' => [], |
|
124
|
|
|
'groups' => [ |
|
125
|
|
|
'template' => '@ProjetNormandieArticle/admin/article_comments_link.html.twig' |
|
126
|
|
|
], |
|
127
|
|
|
] |
|
128
|
|
|
]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
protected function configureShowFields(ShowMapper $show): void |
|
132
|
|
|
{ |
|
133
|
|
|
$show |
|
134
|
|
|
->add('id', null, ['label' => 'article.show.id']) |
|
135
|
|
|
->add('status', null, ['label' => 'article.show.status']) |
|
136
|
|
|
->add('title', null, ['label' => 'article.show.title']) |
|
137
|
|
|
->add('content', null, ['label' => 'article.show.content', 'safe' => true]); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths