|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Action\Action; |
|
6
|
|
|
use LAG\AdminBundle\Action\Responder\EditResponder; |
|
7
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
class EditAction extends Action |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var EditResponder |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $responder; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Action constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param string $name |
|
22
|
|
|
* @param FormFactoryInterface $formFactory |
|
23
|
|
|
* @param EditResponder $responder |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
$name, |
|
27
|
|
|
FormFactoryInterface $formFactory, |
|
28
|
|
|
EditResponder $responder |
|
29
|
|
|
) { |
|
30
|
|
|
$this->name = $name; |
|
31
|
|
|
$this->formFactory = $formFactory; |
|
32
|
|
|
$this->responder = $responder; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Edit and update an entity using the EditForm handler. |
|
37
|
|
|
* |
|
38
|
|
|
* @param Request $request |
|
39
|
|
|
* |
|
40
|
|
|
* @return Response |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __invoke(Request $request) |
|
43
|
|
|
{ |
|
44
|
|
|
// the admin with automatically injected thanks to the KernelSubscriber |
|
45
|
|
|
$this |
|
46
|
|
|
->admin |
|
47
|
|
|
->handleRequest($request) |
|
48
|
|
|
; |
|
49
|
|
|
|
|
50
|
|
|
// create the associated form type |
|
51
|
|
|
$form = $this |
|
52
|
|
|
->formFactory |
|
53
|
|
|
->create( |
|
54
|
|
|
$this->configuration->getParameter('form'), |
|
55
|
|
|
$this->admin->getUniqueEntity(), |
|
56
|
|
|
$this->configuration->getParameter('form_options') |
|
57
|
|
|
) |
|
58
|
|
|
; |
|
59
|
|
|
$form->handleRequest($request); |
|
60
|
|
|
|
|
61
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
62
|
|
|
// save the updated entity |
|
63
|
|
|
$this |
|
64
|
|
|
->admin |
|
65
|
|
|
->save() |
|
66
|
|
|
; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// return a Response using the EditResponder |
|
70
|
|
|
return $this |
|
71
|
|
|
->responder |
|
72
|
|
|
->respond($this->configuration, $this->admin, $form, $request->request->get('submit')) |
|
73
|
|
|
; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|