diff --git a/composer.json b/composer.json
index c9c13ce..0c14d27 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "trexima/cv",
"description": "Bundle provides form for creating CV in european format.",
"type": "symfony-bundle",
- "version": "1.7.2",
+ "version": "1.8.0",
"license": "MIT",
"keywords": ["cv"],
"authors": [
diff --git a/src/Form/Parts/EuropeanCVPartBasicInfoType.php b/src/Form/Parts/EuropeanCVPartBasicInfoType.php
index 96a5f8a..7c48f1e 100644
--- a/src/Form/Parts/EuropeanCVPartBasicInfoType.php
+++ b/src/Form/Parts/EuropeanCVPartBasicInfoType.php
@@ -2,7 +2,6 @@
namespace Trexima\EuropeanCvBundle\Form\Parts;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Extension\Core\DataAccessor\CallbackAccessor;
@@ -16,9 +15,6 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\Form\FormEvent;
-use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -42,7 +38,7 @@
/**
* Basic user info
*/
-class EuropeanCVPartBasicInfoType extends AbstractType implements DataMapperInterface, EventSubscriberInterface
+class EuropeanCVPartBasicInfoType extends AbstractType implements DataMapperInterface
{
private readonly DataMapper $dataMapper;
@@ -81,6 +77,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => t('trexima_european_cv.form_label.sex_label', [], 'trexima_european_cv'),
'placeholder' => false,
])
+ ->add('photo', PhotoType::class, array_merge([
+ 'required' => false,
+ 'mapped' => false,
+ 'label' => false,
+ 'aspect_ratio' => 1,
+ 'max_size' => 16 << 20,
+ 'max_size_message' => t(
+ 'job.max_file_size',
+ ['limit' => 16, 'suffix' => 'MB'],
+ 'validators',
+ ),
+ ], ($options['field_options']['photo'] ?? [])))
->add('firstName', TextType::class, [
'label' => t('trexima_european_cv.form_label.first_name_label', [], 'trexima_european_cv'),
'attr' => [
@@ -215,32 +223,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'placeholder' => t('trexima_european_cv.form_label.description_placeholder', [], 'trexima_european_cv')
]
]);
-
- $builder->addEventSubscriber($this);
- }
-
- public static function getSubscribedEvents(): array
- {
- return [
- FormEvents::PRE_SET_DATA => 'onPreSetData',
- FormEvents::SUBMIT => 'onSubmit',
- ];
- }
-
- public function onPreSetData(FormEvent $formEvent): void
- {
- $this->addPhotoField($formEvent->getForm());
- }
-
- public function onSubmit(FormEvent $formEvent): void
- {
- $form = $formEvent->getForm();
-
- if ($onSubmitCallback = $form->getConfig()->getOption('callback_options')['photo']['on_submit'] ?? null) {
- $onSubmitCallback($form, $formEvent->getData());
- }
-
- $this->addPhotoField($form);
}
/**
@@ -252,7 +234,6 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setDefaults([
'data_class' => EuropeanCV::class,
'field_options' => [],
- 'callback_options' => [],
]);
$resolver->setRequired([
@@ -279,24 +260,9 @@ public function mapDataToForms(mixed $viewData, \Traversable $forms): void
$this->mapPhoto($viewData, $forms);
}
- private function addPhotoField(FormInterface $form): void
+ public function makePhotoUrl(string $photo): string
{
- $options = $form->getConfig()->getOptions();
-
- $form
- ->add('photo', PhotoType::class, array_merge([
- 'required' => false,
- 'mapped' => false,
- 'label' => false,
- 'aspect_ratio' => 1,
- 'max_size' => 16 << 20,
- 'max_size_message' => t(
- 'job.max_file_size',
- ['limit' => 16, 'suffix' => 'MB'],
- 'validators',
- ),
- ], ($options['field_options']['photo'] ?? [])))
- ;
+ return $this->uploadUrl . '/images/' . $photo;
}
private function mapPhoto(EuropeanCV|null $viewData, \Traversable $forms): void
@@ -307,16 +273,15 @@ private function mapPhoto(EuropeanCV|null $viewData, \Traversable $forms): void
}
$photo = $viewData?->getPhoto();
+
if (null === $photo) {
$forms['photo']->setData(null);
return;
}
- $url = $this->uploadUrl . '/images/' . $photo;
-
$photoType = (new Photo())
->setExistingFileId('123')
- ->setExistingFileUrl($url)
+ ->setExistingFileUrl($this->makePhotoUrl($photo))
->setFile(null);
$forms['photo']->setData($photoType);
diff --git a/src/Form/Type/PhotoType.php b/src/Form/Type/PhotoType.php
index d8d631c..6d9fbe7 100644
--- a/src/Form/Type/PhotoType.php
+++ b/src/Form/Type/PhotoType.php
@@ -50,6 +50,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('options', HiddenType::class, [
'required' => false,
'error_bubbling' => true,
+ 'constraints' => [
+ new Assert\Type('array'),
+ new Assert\Collection([
+ 'x' => new Assert\GreaterThanOrEqual(0, message: 'trexima_european_cv.photo.constraint.options.x'),
+ 'y' => new Assert\GreaterThanOrEqual(0, message: 'trexima_european_cv.photo.constraint.options.y'),
+ 'width' => new Assert\GreaterThan(0, message: 'trexima_european_cv.photo.constraint.options.width'),
+ 'height' => new Assert\GreaterThan(0, message: 'trexima_european_cv.photo.constraint.options.height'),
+ 'rotate' => new Assert\Range(min: -360, max: 360, notInRangeMessage: 'trexima_european_cv.photo.constraint.options.rotate'),
+ ], missingFieldsMessage: 'trexima_european_cv.photo.constraint.options'),
+ ],
])
->addEventListener(FormEvents::POST_SET_DATA, $this->postSetData(...));
diff --git a/translations/validators+intl-icu.sk-SK.xlf b/translations/validators+intl-icu.sk-SK.xlf
index 46bbafb..821211a 100644
--- a/translations/validators+intl-icu.sk-SK.xlf
+++ b/translations/validators+intl-icu.sk-SK.xlf
@@ -55,5 +55,41 @@
Prosím, vyplň dátum narodenia v správnom tvare.
+
+
+
+ Pole {field} chýba.
+
+
+
+
+
+ Hodnota pre "X-ovú súradnicu" musí byť väčšia alebo rovná 0
+
+
+
+
+
+ Hodnota pre "Y-ovú súradnicu" musí byť väčšia alebo rovná 0
+
+
+
+
+
+ Šírka musí byť väčšia ako 0
+
+
+
+
+
+ Výška musí byť väčšia ako 0
+
+
+
+
+
+ Uhol otočenia musí byť v rozmedzí -360° až 360°
+
+