1 | <?php |
||
23 | abstract class GenericCRUDElement extends AbstractElement implements CRUDElement |
||
24 | { |
||
25 | /** |
||
26 | * @var \FSi\Component\DataSource\DataSourceFactoryInterface |
||
27 | */ |
||
28 | protected $datasourceFactory; |
||
29 | |||
30 | /** |
||
31 | * @var \FSi\Component\DataGrid\DataGridFactoryInterface |
||
32 | */ |
||
33 | protected $datagridFactory; |
||
34 | |||
35 | /** |
||
36 | * @var \Symfony\Component\Form\FormFactoryInterface |
||
37 | */ |
||
38 | protected $formFactory; |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function getRoute() |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function getSuccessRoute() |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getSuccessRouteParameters() |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function configureOptions(OptionsResolver $resolver) |
||
68 | { |
||
69 | $resolver->setDefaults([ |
||
70 | 'allow_delete' => true, |
||
71 | 'allow_add' => true, |
||
72 | 'template_crud_list' => null, |
||
73 | 'template_crud_create' => null, |
||
74 | 'template_crud_edit' => null, |
||
75 | 'template_list' => function (Options $options) { |
||
76 | return $options['template_crud_list']; |
||
77 | }, |
||
78 | 'template_form' => function (Options $options) { |
||
79 | return $options['template_crud_edit']; |
||
80 | } |
||
81 | ]); |
||
82 | |||
83 | $resolver->setNormalizer('template_crud_create', function (Options $options, $value) { |
||
84 | if ($value !== $options['template_crud_edit']) { |
||
85 | throw new RuntimeException( |
||
86 | 'CRUD admin element options "template_crud_create" and "template_crud_edit" have both to have the same value' |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | return $value; |
||
91 | }); |
||
92 | |||
93 | $resolver->setAllowedTypes('allow_delete', 'bool'); |
||
94 | $resolver->setAllowedTypes('allow_add', 'bool'); |
||
95 | $resolver->setAllowedTypes('template_crud_list', ['null', 'string']); |
||
96 | $resolver->setAllowedTypes('template_crud_create', ['null', 'string']); |
||
97 | $resolver->setAllowedTypes('template_crud_edit', ['null', 'string']); |
||
98 | $resolver->setAllowedTypes('template_list', ['null', 'string']); |
||
99 | $resolver->setAllowedTypes('template_form', ['null', 'string']); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function apply($object) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function setDataGridFactory(DataGridFactoryInterface $factory) |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function setDataSourceFactory(DataSourceFactoryInterface $factory) |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function setFormFactory(FormFactoryInterface $factory) |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | public function createDataGrid() |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function createDataSource() |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | public function createForm($data = null) |
||
190 | |||
191 | /** |
||
192 | * Initialize DataGrid. |
||
193 | * |
||
194 | * @param \FSi\Component\DataGrid\DataGridFactoryInterface $factory |
||
195 | * @return \FSi\Component\DataGrid\DataGridInterface |
||
196 | */ |
||
197 | abstract protected function initDataGrid(DataGridFactoryInterface $factory); |
||
198 | |||
199 | /** |
||
200 | * Initialize DataSource. |
||
201 | * |
||
202 | * @param \FSi\Component\DataSource\DataSourceFactoryInterface $factory |
||
203 | * @return \FSi\Component\DataSource\DataSourceInterface |
||
204 | */ |
||
205 | abstract protected function initDataSource(DataSourceFactoryInterface $factory); |
||
206 | |||
207 | /** |
||
208 | * Initialize create Form. This form will be used in createAction in CRUDController. |
||
209 | * |
||
210 | * @param \Symfony\Component\Form\FormFactoryInterface $factory |
||
211 | * @param mixed $data |
||
212 | * @return \Symfony\Component\Form\FormInterface |
||
213 | */ |
||
214 | abstract protected function initForm(FormFactoryInterface $factory, $data = null); |
||
215 | } |
||
216 |