1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FSi\FixturesBundle\Admin; |
6
|
|
|
|
7
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; |
8
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
9
|
|
|
use FSi\Component\DataGrid\DataGridInterface; |
10
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
11
|
|
|
use FSi\Component\DataSource\DataSourceInterface; |
12
|
|
|
use FSi\FixturesBundle\Entity; |
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType; |
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
15
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
16
|
|
|
use Symfony\Component\Form\FormInterface; |
17
|
|
|
|
18
|
|
|
class Category extends CRUDElement |
19
|
|
|
{ |
20
|
|
|
public function getId(): string |
21
|
|
|
{ |
22
|
|
|
return 'category'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getClassName(): string |
26
|
|
|
{ |
27
|
|
|
return Entity\Category::class; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface |
31
|
|
|
{ |
32
|
|
|
return $factory->createDataGrid($this->getId()) |
33
|
|
|
->addColumn('title', 'text', [ |
34
|
|
|
'label' => 'admin.category.list.title', |
35
|
|
|
'field_mapping' => ['title'], |
36
|
|
|
'editable' => true |
37
|
|
|
])->addColumn('actions', 'action', [ |
38
|
|
|
'label' => 'admin.category.list.actions', |
39
|
|
|
'field_mapping' => ['id'], |
40
|
|
|
'actions' => [ |
41
|
|
|
'news' => [ |
42
|
|
|
'route_name' => 'fsi_admin_list', |
43
|
|
|
'additional_parameters' => ['element' => 'category_news'], |
44
|
|
|
'parameters_field_mapping' => ['parent' => 'id'], |
45
|
|
|
'redirect_uri' => false, |
46
|
|
|
], |
47
|
|
|
'edit' => [ |
48
|
|
|
'route_name' => 'fsi_admin_form', |
49
|
|
|
'additional_parameters' => ['element' => $this->getId()], |
50
|
|
|
'parameters_field_mapping' => ['id' => 'id'] |
51
|
|
|
], |
52
|
|
|
] |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface |
57
|
|
|
{ |
58
|
|
|
return $factory |
59
|
|
|
->createDataSource( |
60
|
|
|
'doctrine-orm', |
61
|
|
|
['entity' => $this->getClassName()], |
62
|
|
|
'news' |
63
|
|
|
)->addField('title', 'text', 'like', [ |
64
|
|
|
'sortable' => false, |
65
|
|
|
'form_options' => [ |
66
|
|
|
'label' => 'admin.category.list.title', |
67
|
|
|
] |
68
|
|
|
])->setMaxResults(10); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface |
72
|
|
|
{ |
73
|
|
|
$builder = $factory->createNamedBuilder( |
74
|
|
|
'category', |
75
|
|
|
FormType::class, |
76
|
|
|
$data, |
77
|
|
|
['data_class' => $this->getClassName()] |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$builder->add( |
81
|
|
|
'title', |
82
|
|
|
TextType::class, |
83
|
|
|
['label' => 'admin.category.list.title'] |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
return $builder->getForm(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|