mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-09 09:54:33 +02:00
Adapter attachment upload forms to the new system
This commit is contained in:
parent
0c33059c4e
commit
3585b8a56a
7 changed files with 32 additions and 22 deletions
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue