<?php
|
declare(strict_types=1);
|
|
namespace App\Form;
|
|
use App\Service\CoverStorage;
|
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\Validator\Constraints\Image;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
|
/**
|
* @extends AbstractType<array{cover: UploadedFile}>
|
*/
|
class CoverType extends AbstractType {
|
private const int MAX_PIXELS = 20_000_000;
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void {
|
$builder
|
->add('cover', FileType::class, [
|
'label' => 'cover_file_header',
|
'attr' => ['accept' => implode(',', array_keys(CoverStorage::EXTENSIONS))],
|
'constraints' => [
|
new NotNull(),
|
new Image(
|
maxSize: '10M',
|
mimeTypes: array_keys(CoverStorage::EXTENSIONS),
|
maxPixels: self::MAX_PIXELS,
|
detectCorrupted: true,
|
),
|
],
|
])
|
->add('save', SubmitType::class, ['label' => 'cover_action_upload']);
|
}
|
}
|