/
AleksWork
/
diary_plants
Обзор
Документация
Войти
/
AleksWork
/
diary_plants
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Controller/Web/Dashboard/Image/EditImage/Manager.php
76 строк
3 KB
AlexeySerov
Add fields name to construct in entity edit manager
25 май 2026, 16:45
25 май 2026, 16:45
aff7df2
Код
Авторство
О чём код?
<?php namespace App\Controller\Web\Dashboard\Image\EditImage; use App\Domain\Entity\Attachment; use App\Controller\Form\ImageType; use App\Domain\Service\AttachmentService; use Symfony\Component\HttpFoundation\Request; use App\Domain\Exception\AccessDeniedException; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Contracts\Translation\TranslatorInterface; use App\Application\Security\Voter\GroupOwnershipVoter; use App\Controller\Web\Dashboard\Image\EditImage\Input\EditImageDTO; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; final class Manager { public function __construct( private readonly AttachmentService $attachmentService, private readonly FormFactoryInterface $formFactory, private readonly TranslatorInterface $translator, private readonly AuthorizationCheckerInterface $authChecker ) { } public function editFormData(Request $request, Attachment $attachment): array { if (!$this->authChecker->isGranted(GroupOwnershipVoter::EDIT, $attachment)) { $message = $this->translator->trans('security.access_denied.edit'); throw new AccessDeniedException($message); } $groupId = $attachment->getGroup()->getId(); $formData = new EditImageDTO( groupId: $groupId, isShown: $attachment->getDisplaySettings()->isShown(), filename: $attachment->getFileInfo()->getFilename(), path: $attachment->getFileInfo()->getPath(), mimeType: $attachment->getFileInfo()->getMimeType(), alt: $attachment->getDisplaySettings()->getAlt(), title: $attachment->getDisplaySettings()->getTitle(), fileDate: $attachment->getFileInfo()->getFileDate(), description: $attachment->getDisplaySettings()->getDescription(), attachableId: (int) $attachment->getTarget()->getAttachableId(), attachableType: $attachment->getTarget()->getAttachableType()->value, imageFile: null ); $form = $this->formFactory->create(ImageType::class, $formData); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var EditImageDTO $editImageDTO */ $editImageDTO = $form->getData(); if (!$editImageDTO->groupId) { $editImageDTO->groupId = $groupId; } $data = $request->request->all()['image'] ?? []; $editImageDTO->isShown = (bool) ($data['isShown'] ?? false); $this->attachmentService->updateFromEditImageDTO($attachment, $editImageDTO); $message = $this->translator->trans('image.flash.updated', [], 'messages'); $request->getSession()->getFlashBag()->add('success', $message); return ['success' => true]; } return [ 'form' => $form->createView(), 'image' => $attachment ]; } }