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\DataGrid\NewsDataGridBuilder; |
13
|
|
|
use FSi\FixturesBundle\DataSource\NewsDataSourceBuilder; |
14
|
|
|
use FSi\FixturesBundle\Entity; |
15
|
|
|
use FSi\FixturesBundle\Form\NewsType; |
16
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
17
|
|
|
use Symfony\Component\Form\FormInterface; |
18
|
|
|
|
19
|
|
|
class News extends CRUDElement |
20
|
|
|
{ |
21
|
|
|
public function getId(): string |
22
|
|
|
{ |
23
|
|
|
return 'news'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getClassName(): string |
27
|
|
|
{ |
28
|
|
|
return Entity\News::class; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface |
32
|
|
|
{ |
33
|
|
|
$datagrid = $factory->createDataGrid($this->getId()); |
34
|
|
|
|
35
|
|
|
NewsDataGridBuilder::buildNewsDataGrid($datagrid); |
36
|
|
|
|
37
|
|
|
$datagrid->addColumn('actions', 'action', [ |
38
|
|
|
'label' => 'admin.news.list.actions', |
39
|
|
|
'field_mapping' => ['id'], |
40
|
|
|
'actions' => [ |
41
|
|
|
'edit' => [ |
42
|
|
|
'route_name' => 'fsi_admin_form', |
43
|
|
|
'additional_parameters' => ['element' => $datagrid->getName()], |
44
|
|
|
'parameters_field_mapping' => ['id' => 'id'] |
45
|
|
|
], |
46
|
|
|
'display' => ['element' => DisplayNews::ID] |
47
|
|
|
] |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
return $datagrid; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface |
54
|
|
|
{ |
55
|
|
|
$datasource = $factory->createDataSource( |
56
|
|
|
'doctrine-orm', |
57
|
|
|
['entity' => $this->getClassName()], |
58
|
|
|
$this->getId() |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
NewsDataSourceBuilder::buildNewsDataSource($datasource); |
62
|
|
|
|
63
|
|
|
return $datasource; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface |
67
|
|
|
{ |
68
|
|
|
return $factory->createNamed( |
69
|
|
|
'news', |
70
|
|
|
NewsType::class, |
71
|
|
|
$data |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|