| @@ 8-56 (lines=49) @@ | ||
| 5 | use Symfony\Component\HttpFoundation\Request; |
|
| 6 | use Symfony\Component\HttpFoundation\Response; |
|
| 7 | ||
| 8 | class CreateAction extends Action |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * Create an action using the create action form handler. |
|
| 12 | * |
|
| 13 | * @param Request $request |
|
| 14 | * |
|
| 15 | * @return Response |
|
| 16 | */ |
|
| 17 | public function __invoke(Request $request) |
|
| 18 | { |
|
| 19 | // the Admin with auto injected with the KernelSubscriber |
|
| 20 | $this |
|
| 21 | ->admin |
|
| 22 | ->handleRequest($request) |
|
| 23 | ; |
|
| 24 | // create the new entity |
|
| 25 | $entity = $this |
|
| 26 | ->admin |
|
| 27 | ->create() |
|
| 28 | ; |
|
| 29 | // create the associated form type |
|
| 30 | $formType = $this |
|
| 31 | ->configuration |
|
| 32 | ->getParameter('form') |
|
| 33 | ; |
|
| 34 | $formOptions = $this |
|
| 35 | ->configuration |
|
| 36 | ->getParameter('form_options') |
|
| 37 | ; |
|
| 38 | $form = $this |
|
| 39 | ->formFactory |
|
| 40 | ->create($formType, $entity, $formOptions) |
|
| 41 | ; |
|
| 42 | $form->handleRequest($request); |
|
| 43 | ||
| 44 | if ($form->isSubmitted() && $form->isValid()) { |
|
| 45 | $this |
|
| 46 | ->admin |
|
| 47 | ->save() |
|
| 48 | ; |
|
| 49 | } |
|
| 50 | ||
| 51 | return $this |
|
| 52 | ->responder |
|
| 53 | ->respond($this->configuration, $this->admin, $form, $request) |
|
| 54 | ; |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 8-52 (lines=45) @@ | ||
| 5 | use Symfony\Component\HttpFoundation\Request; |
|
| 6 | use Symfony\Component\HttpFoundation\Response; |
|
| 7 | ||
| 8 | class DeleteAction extends Action |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * Delete an entity. |
|
| 12 | * |
|
| 13 | * @param Request $request |
|
| 14 | * |
|
| 15 | * @return Response |
|
| 16 | */ |
|
| 17 | public function __invoke(Request $request) |
|
| 18 | { |
|
| 19 | // the Admin with auto injected with the KernelSubscriber |
|
| 20 | $this |
|
| 21 | ->admin |
|
| 22 | ->handleRequest($request) |
|
| 23 | ; |
|
| 24 | // create the configured form type |
|
| 25 | $formType = $this |
|
| 26 | ->configuration |
|
| 27 | ->getParameter('form') |
|
| 28 | ; |
|
| 29 | $formOptions = $this |
|
| 30 | ->configuration |
|
| 31 | ->getParameter('form_options') |
|
| 32 | ; |
|
| 33 | $form = $this |
|
| 34 | ->formFactory |
|
| 35 | ->create($formType, $this->admin->getUniqueEntity(), $formOptions) |
|
| 36 | ; |
|
| 37 | $form->handleRequest($request); |
|
| 38 | ||
| 39 | if ($form->isSubmitted() && $form->isValid()) { |
|
| 40 | // remove the entity |
|
| 41 | $this |
|
| 42 | ->admin |
|
| 43 | ->remove() |
|
| 44 | ; |
|
| 45 | } |
|
| 46 | ||
| 47 | return $this |
|
| 48 | ->responder |
|
| 49 | ->respond($this->configuration, $this->admin, $form, $request) |
|
| 50 | ; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||