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