Completed
Pull Request — master (#90)
by Arnaud
02:34
created

DeleteResponder::respond()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 10
Ratio 43.48 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 10
loc 23
ccs 8
cts 8
cp 1
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 14
nc 2
nop 3
crap 3
1
<?php
2
3
namespace LAG\AdminBundle\Action\Responder;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Admin\AdminInterface;
7
use LAG\AdminBundle\Routing\RouteNameGenerator;
8
use Symfony\Component\Form\FormInterface;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class DeleteResponder extends AbstractResponder
13
{
14
    /**
15
     * Display the delete form (to ensure not deleting entities just with an url call) and redirect to the list Action
16
     * when the form is submitted.
17
     *
18
     * @param ActionConfiguration $configuration
19
     * @param AdminInterface      $admin
20 2
     * @param FormInterface       $form
21
     *
22
     * @return Response
23
     */
24
    public function respond(
25 2
        ActionConfiguration $configuration,
26
        AdminInterface $admin,
27 2
        FormInterface $form
28
    ) {
29 1
        $template = $configuration->getParameter('template');
30 1
        
31 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
32
            $generator = new RouteNameGenerator();
33 1
    
34
            $url = $this
35
                ->router
36 1
                ->generate($generator->generate('list', $admin->getName(), $admin->getConfiguration()))
37 1
            ;
38 1
39
            return new RedirectResponse($url);
40
        }
41
        
42
        return $this->render($template, [
43
            'admin' => $admin,
44
            'form' => $form->createView(),
45
        ]);
46
    }
47
}
48