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 Symfony\Component\Form\FormFactoryInterface; |
9
|
|
|
|
10
|
|
|
class Category extends CRUDElement |
11
|
|
|
{ |
12
|
|
|
public function getId() |
13
|
|
|
{ |
14
|
|
|
return 'category'; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function getClassName() |
18
|
|
|
{ |
19
|
|
|
return 'FSi\FixturesBundle\Entity\Category'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory) |
23
|
|
|
{ |
24
|
|
|
/* @var $datagrid \FSi\Component\DataGrid\DataGrid */ |
25
|
|
|
$datagrid = $factory->createDataGrid('category'); |
26
|
|
|
$datagrid->addColumn('title', 'text', [ |
27
|
|
|
'label' => 'admin.category.list.title', |
28
|
|
|
'field_mapping' => ['title'], |
29
|
|
|
'editable' => true |
30
|
|
|
]); |
31
|
|
|
$datagrid->addColumn('actions', 'action', [ |
32
|
|
|
'label' => 'admin.category.list.actions', |
33
|
|
|
'field_mapping' => ['id'], |
34
|
|
|
'actions' => [ |
35
|
|
|
'news' => [ |
36
|
|
|
'route_name' => "fsi_admin_crud_list", |
37
|
|
|
'additional_parameters' => ['element' => 'category_news'], |
38
|
|
|
'parameters_field_mapping' => ['parent' => 'id'], |
39
|
|
|
'redirect_uri' => false, |
40
|
|
|
], |
41
|
|
|
'edit' => [ |
42
|
|
|
'route_name' => "fsi_admin_crud_edit", |
43
|
|
|
'additional_parameters' => ['element' => $this->getId()], |
44
|
|
|
'parameters_field_mapping' => ['id' => 'id'] |
45
|
|
|
], |
46
|
|
|
] |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
return $datagrid; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory) |
53
|
|
|
{ |
54
|
|
|
/* @var $datasource \FSi\Component\DataSource\DataSource */ |
55
|
|
|
$datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news'); |
56
|
|
|
$datasource->addField('title', 'text', 'like', [ |
57
|
|
|
'sortable' => false, |
58
|
|
|
'form_options' => [ |
59
|
|
|
'label' => 'admin.category.list.title', |
60
|
|
|
] |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$datasource->setMaxResults(10); |
64
|
|
|
|
65
|
|
|
return $datasource; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null) |
69
|
|
|
{ |
70
|
|
|
$builder = $factory->createNamedBuilder('category', 'form', $data, [ |
71
|
|
|
'data_class' => $this->getClassName() |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
$builder->add('title', 'text', [ |
75
|
|
|
'label' => 'admin.category.list.title', |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
return $builder->getForm(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|