1 | <?php |
||
17 | class ActionConfiguration extends Configuration |
||
18 | { |
||
19 | /** |
||
20 | * Related Action name. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $actionName; |
||
25 | |||
26 | /** |
||
27 | * @var AdminConfiguration |
||
28 | */ |
||
29 | private $adminConfiguration; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $adminName; |
||
35 | |||
36 | /** |
||
37 | * ActionConfiguration constructor. |
||
38 | * |
||
39 | * @param string $actionName |
||
40 | * @param string $adminName |
||
41 | * @param AdminConfiguration $adminConfiguration |
||
42 | */ |
||
43 | public function __construct(string $actionName, string $adminName, AdminConfiguration $adminConfiguration) |
||
44 | { |
||
45 | parent::__construct(); |
||
46 | |||
47 | $this->actionName = $actionName; |
||
48 | $this->adminConfiguration = $adminConfiguration; |
||
49 | $this->adminName = $adminName; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Define allowed parameters and values for this configuration, using optionsResolver component. |
||
54 | * |
||
55 | * @param OptionsResolver $resolver |
||
56 | */ |
||
57 | public function configureOptions(OptionsResolver $resolver) |
||
58 | { |
||
59 | $resolver |
||
60 | ->setDefaults([ |
||
61 | 'title' => $this->getDefaultTitle(), |
||
62 | 'class' => Action::class, |
||
63 | 'fields' => [], |
||
64 | 'permissions' => [ |
||
65 | 'ROLE_ADMIN', |
||
66 | ], |
||
67 | 'export' => [], |
||
68 | 'order' => [], |
||
69 | 'route' => $this->generateRouteName(), |
||
70 | 'route_parameters' => [], |
||
71 | 'route_path' => $this->getDefaultRoutePath(), |
||
72 | 'route_requirements' => [], |
||
73 | 'route_defaults' => [ |
||
74 | '_controller' => AdminAction::class, |
||
75 | ], |
||
76 | 'icon' => null, |
||
77 | 'load_strategy' => LAGAdminBundle::LOAD_STRATEGY_NONE, |
||
78 | 'pager' => false, |
||
79 | 'max_per_page' => 30, |
||
80 | 'criteria' => [], |
||
81 | 'filters' => [], |
||
82 | 'menus' => [], |
||
83 | 'template' => $this->getDefaultTemplate(), |
||
84 | 'sortable' => false, |
||
85 | 'string_length' => $this->adminConfiguration->getParameter('string_length'), |
||
86 | 'string_length_truncate' => $this->adminConfiguration->getParameter('string_length_truncate'), |
||
87 | 'date_format' => $this->adminConfiguration->getParameter('date_format'), |
||
88 | 'use_form' => false, |
||
89 | ]) |
||
90 | ->setAllowedTypes('title', 'string') |
||
91 | ->setAllowedTypes('class', 'string') |
||
92 | ->setAllowedTypes('fields', 'array') |
||
93 | ->setAllowedTypes('permissions', 'array') |
||
94 | ->setAllowedTypes('export', 'array') |
||
95 | ->setAllowedTypes('order', 'array') |
||
96 | ->setAllowedTypes('route', 'string') |
||
97 | ->setAllowedTypes('route_parameters', 'array') |
||
98 | ->setAllowedTypes('route_path', 'string') |
||
99 | ->setAllowedTypes('route_defaults', 'array') |
||
100 | ->setAllowedTypes('route_requirements', 'array') |
||
101 | ->setAllowedTypes('string_length', 'integer') |
||
102 | ->setAllowedTypes('string_length_truncate', 'string') |
||
103 | ->setNormalizer('fields', $this->getFieldsNormalizer()) |
||
104 | ->setNormalizer('order', $this->getOrderNormalizer()) |
||
105 | ->setNormalizer('load_strategy', $this->getLoadStrategyNormalizer()) |
||
106 | ->setNormalizer('criteria', $this->getCriteriaNormalizer()) |
||
107 | ->setNormalizer('menus', $this->getMenuNormalizer()) |
||
108 | ->setNormalizer('filters', $this->getFiltersNormalizer()) |
||
109 | ->setNormalizer('route_defaults', $this->getRouteDefaultNormalizer()) |
||
110 | ->setAllowedValues('load_strategy', [ |
||
111 | LAGAdminBundle::LOAD_STRATEGY_NONE, |
||
112 | LAGAdminBundle::LOAD_STRATEGY_UNIQUE, |
||
113 | LAGAdminBundle::LOAD_STRATEGY_MULTIPLE, |
||
114 | ]) |
||
115 | ->setAllowedValues('pager', [ |
||
116 | 'pagerfanta', |
||
117 | false, |
||
118 | null, |
||
119 | ]) |
||
120 | ; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Generate an admin route name using the pattern in the configuration. |
||
125 | * |
||
126 | * @return string |
||
127 | * |
||
128 | * @throws Exception |
||
129 | */ |
||
130 | private function generateRouteName(): string |
||
148 | |||
149 | /** |
||
150 | * Return the field normalizer. It will transform null configuration into array to allow field type guessing |
||
151 | * working. |
||
152 | * |
||
153 | * @return Closure |
||
154 | */ |
||
155 | private function getFieldsNormalizer() |
||
172 | |||
173 | /** |
||
174 | * Return the order normalizer. It will check if the order value passed are valid. |
||
175 | * |
||
176 | * @return Closure |
||
177 | */ |
||
178 | private function getOrderNormalizer() |
||
195 | |||
196 | /** |
||
197 | * Return the load strategy normalizer. It will set the default strategy according to the action name, if no value |
||
198 | * is provided. |
||
199 | * |
||
200 | * @return Closure |
||
201 | */ |
||
202 | private function getLoadStrategyNormalizer() |
||
218 | |||
219 | /** |
||
220 | * Return the menu normalizer. It will transform false values into an empty array to allow default menu |
||
221 | * configuration working. |
||
222 | * |
||
223 | * @return Closure |
||
224 | */ |
||
225 | private function getMenuNormalizer() |
||
236 | |||
237 | /** |
||
238 | * Return the criteria normalizer. It will add the id parameters for the edit and delete actions if no value is |
||
239 | * provided. |
||
240 | * |
||
241 | * @return Closure |
||
242 | */ |
||
243 | private function getCriteriaNormalizer() |
||
262 | |||
263 | /** |
||
264 | * @return string |
||
265 | */ |
||
266 | public function getAdminName(): string |
||
270 | |||
271 | /** |
||
272 | * @return string |
||
273 | */ |
||
274 | public function getActionName(): string |
||
278 | |||
279 | /** |
||
280 | * @return AdminConfiguration |
||
281 | */ |
||
282 | public function getAdminConfiguration(): AdminConfiguration |
||
286 | |||
287 | /** |
||
288 | * Return the filters normalizer. |
||
289 | * |
||
290 | * @return Closure |
||
291 | */ |
||
292 | private function getFiltersNormalizer() |
||
317 | |||
318 | private function getRouteDefaultNormalizer() |
||
330 | |||
331 | /** |
||
332 | * Return the default title using the configured translation pattern. |
||
333 | * |
||
334 | * @return string |
||
335 | */ |
||
336 | private function getDefaultTitle() |
||
357 | |||
358 | /** |
||
359 | * Return the default route path according to the action name. |
||
360 | * |
||
361 | * @return string |
||
362 | */ |
||
363 | private function getDefaultRoutePath() |
||
378 | |||
379 | private function getDefaultTemplate() |
||
394 | |||
395 | private function isActionInMapping(array $mapping) |
||
399 | } |
||
400 |