Feat: Add funtion to rename uploaded documents
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class RenameController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/rename/{uuid}', name: 'app_admin_document_rename')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder($upload, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->add('displayName', TextType::class, [
|
||||
'label' => 'angezeigter Name',
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurden umbenannt');
|
||||
$this->logger->info('Rename document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/rename.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user