Feat: Add edit function for trainings
This commit is contained in:
@@ -44,7 +44,7 @@ class CreateController extends AbstractController
|
||||
$redirectUrl = $this->generateUrl('app_admin_system_training_index');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
$content = $this->renderView('admin/system/training/create.html.twig', [
|
||||
$content = $this->renderView('admin/system/training/form.html.twig', [
|
||||
'form' => $form
|
||||
]);
|
||||
$response->setContent($content);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\System\Training;
|
||||
|
||||
use App\Entity\Training;
|
||||
use App\Form\TrainingType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/system/training/edit/{id}', name: 'app_admin_system_training_edit')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function index(Training $training, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$action = $this->generateUrl('app_admin_system_training_create');
|
||||
|
||||
$form = $this->createForm(TrainingType::class, $training, ['action' => $action, 'ajax_submit' => true]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Fortbildung wurde aktualisiert');
|
||||
$this->logger->info('Edit training', [
|
||||
'training' => $training->getName(),
|
||||
]);
|
||||
|
||||
$redirectUrl = $this->generateUrl('app_admin_system_training_index');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
$content = $this->renderView('admin/system/training/form.html.twig', [
|
||||
'form' => $form
|
||||
]);
|
||||
$response->setContent($content);
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,14 @@
|
||||
}) }}>
|
||||
{{ icon('delete') }}
|
||||
</button>
|
||||
<button type="button"
|
||||
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||
{{ stimulus_action('modal-button', 'ajax', null, {
|
||||
'title': 'Fortbildung bearbeiten',
|
||||
'url': path('app_admin_system_training_edit', { 'id': training.id })
|
||||
}) }}>
|
||||
{{ icon('edit') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user