Completed
Pull Request — master (#90)
by Arnaud
05:12 queued 02:13
created

DeleteResponder::respond()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

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