Total Complexity | 11 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class ViewHelper |
||
11 | { |
||
12 | public function shouldRedirect( |
||
13 | Request $request, |
||
14 | AdminConfiguration $configuration, |
||
15 | AdminInterface $admin, |
||
16 | ActionInterface $action, |
||
17 | string $formName = '' |
||
18 | ) { |
||
19 | if (!$this->isFormValid($admin, $configuration, $formName)) { |
||
20 | return false; |
||
21 | } |
||
22 | |||
23 | // When the create form is submitted, the user should be redirected to the edit action after saving the form |
||
24 | // data |
||
25 | if ('create' === $action->getName()) { |
||
26 | return true; |
||
27 | } |
||
28 | |||
29 | // When the delete form is submitted, we should redirect to the list action |
||
30 | if ('delete' === $action->getName()) { |
||
31 | return true; |
||
32 | } |
||
33 | |||
34 | if (!$request->get('submit_and_redirect')) { |
||
35 | return false; |
||
36 | } |
||
37 | |||
38 | if ('submit_and_redirect' !== $request->get('submit_and_redirect')) { |
||
39 | return false; |
||
40 | } |
||
41 | |||
42 | return true; |
||
43 | } |
||
44 | |||
45 | private function isFormValid(AdminInterface $admin, AdminConfiguration $configuration, string $formName): bool |
||
65 | } |
||
66 | } |
||
67 |