1 | <?php |
||
20 | class Person extends CRUDElement |
||
21 | { |
||
22 | public function getId() |
||
23 | { |
||
24 | return 'person'; |
||
25 | } |
||
26 | |||
27 | public function getClassName() |
||
28 | { |
||
29 | return 'FSi\FixturesBundle\Entity\Person'; |
||
30 | } |
||
31 | |||
32 | public function createDataGrid() |
||
33 | { |
||
34 | $datagrid = $this->initDataGrid($this->datagridFactory); |
||
35 | |||
36 | if (!is_object($datagrid) || !$datagrid instanceof DataGridInterface) { |
||
37 | throw new RuntimeException('initDataGrid should return instanceof FSi\\Component\\DataGrid\\DataGridInterface'); |
||
38 | } |
||
39 | |||
40 | if (!$datagrid->hasColumnType('batch')) { |
||
41 | $datagrid->addColumn('batch', 'batch', [ |
||
42 | 'actions' => [ |
||
43 | 'delete' => [ |
||
44 | 'route_name' => 'fsi_admin_batch', |
||
45 | 'additional_parameters' => ['element' => $this->getId()], |
||
46 | 'label' => 'crud.list.batch.delete' |
||
47 | ] |
||
48 | ], |
||
49 | 'display_order' => -1000 |
||
50 | ]); |
||
51 | } |
||
52 | |||
53 | return $datagrid; |
||
54 | } |
||
55 | |||
56 | protected function initDataGrid(DataGridFactoryInterface $factory) |
||
57 | { |
||
58 | $datagrid = $factory->createDataGrid($this->getId()); |
||
59 | |||
60 | $datagrid->addColumn('email', 'text', [ |
||
61 | 'label' => 'admin.email' |
||
62 | ]); |
||
63 | |||
64 | $datagrid->addColumn('actions', 'action', [ |
||
65 | 'label' => 'admin.news.list.actions', |
||
66 | 'field_mapping' => ['id'], |
||
67 | 'actions' => [ |
||
68 | 'edit' => [ |
||
69 | 'route_name' => "fsi_admin_crud_edit", |
||
70 | 'additional_parameters' => ['element' => $this->getId()], |
||
71 | 'parameters_field_mapping' => ['id' => 'id'] |
||
72 | ] |
||
73 | ] |
||
74 | ]); |
||
75 | |||
76 | return $datagrid; |
||
77 | } |
||
78 | |||
79 | protected function initDataSource(DataSourceFactoryInterface $factory) |
||
80 | { |
||
81 | return $factory->createDataSource( |
||
82 | 'doctrine', |
||
83 | ['entity' => $this->getClassName()], |
||
84 | $this->getId() |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | protected function initForm(FormFactoryInterface $factory, $data = null) |
||
89 | { |
||
90 | $builder = $factory->createNamedBuilder( |
||
91 | 'person', |
||
92 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'), |
||
93 | $data, |
||
94 | ['data_class' => $this->getClassName()] |
||
95 | ); |
||
96 | |||
97 | $builder->add( |
||
98 | 'email', |
||
99 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'), |
||
100 | ['label' => 'admin.email'] |
||
101 | ); |
||
102 | |||
103 | return $builder->getForm(); |
||
104 | } |
||
105 | } |
||
106 |