Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Edit | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
5.00 | |
0.00% |
0 / 1 |
| __invoke | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
5.00 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\PaymentMethods; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Entity\PaymentMethod; |
| 9 | use App\Form\PaymentMethodType; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Symfony\Component\HttpFoundation\Request; |
| 12 | use Symfony\Component\HttpFoundation\Response; |
| 13 | use Symfony\Component\Routing\Attribute\Route; |
| 14 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 15 | |
| 16 | #[IsGranted('ROLE_ADMIN')] |
| 17 | #[Route(path: '/payment-methods/edit/{id}', name: 'payment_methods_edit', methods: ['GET', 'POST'])] |
| 18 | class Edit extends BaseController |
| 19 | { |
| 20 | public function __invoke( |
| 21 | PaymentMethod $data, |
| 22 | Request $request, |
| 23 | EntityManagerInterface $entityManager, |
| 24 | ): Response |
| 25 | { |
| 26 | $form = $this->createForm(PaymentMethodType::class, $data); |
| 27 | $form->handleRequest($request); |
| 28 | if ($form->isSubmitted() && $form->isValid()) { |
| 29 | $entityManager->persist($data); |
| 30 | $entityManager->flush(); |
| 31 | |
| 32 | $this->addFlash('success', 'Payment method has been updated'); |
| 33 | |
| 34 | return $this->redirectToRoute('payment_methods_index'); |
| 35 | } |
| 36 | |
| 37 | $template = $request->query->get('ajax') |
| 38 | ? '_form.html.twig' |
| 39 | : 'form.html.twig'; |
| 40 | |
| 41 | return $this->render( |
| 42 | 'payment-methods/'.$template, |
| 43 | [ |
| 44 | 'form' => $form, |
| 45 | 'data' => $data, |
| 46 | ], |
| 47 | new Response(null, $form->isSubmitted() ? 422 : 200) |
| 48 | ); |
| 49 | } |
| 50 | } |