Files
myep-team/src/Controller/Admin/Assignment/EditController.php
T

54 lines
1.8 KiB
PHP

<?php
namespace App\Controller\Admin\Assignment;
use App\Entity\Assignment;
use App\Form\AssignmentType;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\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/assignment/edit/{uuid}', name: 'app_admin_assignment_edit')]
#[IsGranted('EDIT', subject: 'assignment')]
public function index(Assignment $assignment, Request $request): Response
{
$form = $this->createForm(
AssignmentType::class,
$assignment,
[
'pickup_form_url' => $this->generateUrl('app_admin_assignment_pickup_form'),
]
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->addFlash('success', 'Der Einsatz wurde aktualisiert');
$this->logger->info('Edit assignment', [
'assignment_id' => $assignment->getId(),
'destination' => (string) $assignment->getDestination(),
'job_profile' => $assignment->getJobProfile()->getName(),
]);
return $this->redirectToRoute('app_admin_assignment_index');
}
return $this->render('admin/assignment/edit.html.twig', [
'form' => $form->createView(),
]);
}
}