1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FSi\FixturesBundle\Admin; |
4
|
|
|
|
5
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; |
6
|
|
|
use FSi\Bundle\AdminBundle\Form\TypeSolver; |
7
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
8
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
9
|
|
|
use FSi\FixturesBundle\DataGrid\NewsDataGridBuilder; |
10
|
|
|
use FSi\FixturesBundle\DataSource\NewsDataSourceBuilder; |
11
|
|
|
use FSi\FixturesBundle\Form\NewsType; |
12
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
13
|
|
|
|
14
|
|
|
class News extends CRUDElement |
15
|
|
|
{ |
16
|
|
|
public function getId() |
17
|
|
|
{ |
18
|
|
|
return 'news'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getClassName() |
22
|
|
|
{ |
23
|
|
|
return 'FSi\FixturesBundle\Entity\News'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory) |
27
|
|
|
{ |
28
|
|
|
/* @var $datagrid \FSi\Component\DataGrid\DataGrid */ |
29
|
|
|
$datagrid = $factory->createDataGrid('news'); |
30
|
|
|
|
31
|
|
|
NewsDataGridBuilder::buildNewsDataGrid($datagrid); |
32
|
|
|
|
33
|
|
|
$datagrid->addColumn('actions', 'action', [ |
34
|
|
|
'label' => 'admin.news.list.actions', |
35
|
|
|
'field_mapping' => ['id'], |
36
|
|
|
'actions' => [ |
37
|
|
|
'edit' => [ |
38
|
|
|
'route_name' => "fsi_admin_crud_edit", |
39
|
|
|
'additional_parameters' => ['element' => $datagrid->getName()], |
40
|
|
|
'parameters_field_mapping' => ['id' => 'id'] |
41
|
|
|
], |
42
|
|
|
'display' => ['element' => DisplayNews::ID] |
43
|
|
|
] |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
return $datagrid; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory) |
50
|
|
|
{ |
51
|
|
|
/* @var $datasource \FSi\Component\DataSource\DataSource */ |
52
|
|
|
$datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news'); |
53
|
|
|
|
54
|
|
|
NewsDataSourceBuilder::buildNewsDataSource($datasource); |
55
|
|
|
|
56
|
|
|
return $datasource; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null) |
60
|
|
|
{ |
61
|
|
|
return $factory->createNamed( |
62
|
|
|
'news', |
63
|
|
|
TypeSolver::getFormType('FSi\FixturesBundle\Form\NewsType', new NewsType()), |
64
|
|
|
$data |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|