Adapter attachment upload forms to the new system

This commit is contained in:
Jan Böhmer 2024-03-03 18:52:06 +01:00
parent 0c33059c4e
commit 3585b8a56a
7 changed files with 32 additions and 22 deletions

View file

@ -36,7 +36,6 @@ use App\ApiPlatform\DocumentedAPIProperty;
use App\ApiPlatform\Filter\EntityFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\ApiPlatform\HandleAttachmentsUploadsProcessor;
use App\EntityListeners\AttachmentUploadListener;
use App\Repository\AttachmentRepository;
use App\EntityListeners\AttachmentDeleteListener;
use Doctrine\DBAL\Types\Types;

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Attribute\Groups;
@ -54,4 +55,23 @@ class AttachmentUpload
public readonly ?bool $becomePreviewIfEmpty = true,
) {
}
/**
* Creates an AttachmentUpload object from an Attachment FormInterface
* @param FormInterface $form
* @return AttachmentUpload
*/
public static function fromAttachmentForm(FormInterface $form): AttachmentUpload
{
if (!$form->has('file')) {
throw new \InvalidArgumentException('The form does not have a file field. Is it an attachment form?');
}
return new self(
file: $form->get('file')->getData(),
downloadUrl: $form->get('downloadURL')->getData(),
private: $form->get('secureFile')->getData()
);
}
}