Code Duplication    Length = 49-52 lines in 2 locations

src/LAG/AdminBundle/Action/Responder/CreateResponder.php 1 location

@@ 12-63 (lines=52) @@
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class CreateResponder extends AbstractResponder
13
{
14
    /**
15
     * @param ActionConfiguration $configuration
16
     * @param AdminInterface      $admin
17
     * @param FormInterface       $form
18
     * @param Request             $request
19
     *
20
     * @return Response
21
     */
22
    public function respond(
23
        ActionConfiguration $configuration,
24
        AdminInterface $admin,
25
        FormInterface $form,
26
        Request $request
27
    ) {
28
        $template = $configuration->getParameter('template');
29
        
30
        // if the form is submitted and validated, the user should be redirected
31
        if ($form->isSubmitted() && $form->isValid()) {
32
            $submitButton = $request
33
                ->request
34
                ->get('submit')
35
            ;
36
            
37
            // if the save button is pressed, the user will stay on the edit view
38
            if ('save' === $submitButton) {
39
                $url = $this
40
                    ->router
41
                    ->generate($admin->generateRouteName('edit'), [
42
                        'id' => $admin->getUniqueEntity()->getId(),
43
                    ])
44
                ;
45
    
46
                return new RedirectResponse($url);
47
            } else {
48
                // otherwise the user will be redirected to the list view
49
                $url = $this
50
                    ->router
51
                    ->generate($admin->generateRouteName('list'))
52
                ;
53
    
54
                return new RedirectResponse($url);
55
            }
56
        }
57
        
58
        return $this->render($template, [
59
            'admin' => $admin,
60
            'form' => $form->createView(),
61
        ]);
62
    }
63
}
64

src/LAG/AdminBundle/Action/Responder/EditResponder.php 1 location

@@ 11-59 (lines=49) @@
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class EditResponder extends AbstractResponder
12
{
13
    /**
14
     * Display the edit form and redirect if required when the form is submitted.
15
     *
16
     * @param ActionConfiguration $configuration
17
     * @param AdminInterface      $admin
18
     * @param FormInterface       $form
19
     * @param                     $submitButtonName
20
     *
21
     * @return Response|RedirectResponse
22
     */
23
    public function respond(
24
        ActionConfiguration $configuration,
25
        AdminInterface $admin,
26
        FormInterface $form,
27
        $submitButtonName
28
    ) {
29
        $template = $configuration->getParameter('template');
30
        
31
        // if the form is submitted and validated, the user should be redirected
32
        if ($form->isSubmitted() && $form->isValid()) {
33
            // if the save button is pressed, the user will stay on the edit view
34
            if ('save' === $submitButtonName) {
35
                $url = $this
36
                    ->router
37
                    ->generate($admin->generateRouteName('edit'), [
38
                        'id' => $admin->getUniqueEntity()->getId(),
39
                    ])
40
                ;
41
                
42
                return new RedirectResponse($url);
43
            } else {
44
                // otherwise the user will be redirected to the list view
45
                $url = $this
46
                    ->router
47
                    ->generate($admin->generateRouteName('list'))
48
                ;
49
                
50
                return new RedirectResponse($url);
51
            }
52
        }
53
        
54
        return $this->render($template, [
55
            'admin' => $admin,
56
            'form' => $form->createView(),
57
        ]);
58
    }
59
}
60