<?php
declare(strict_types=1);
namespace App\Form\Type\Admin;
use App\Entity\Configurator\Font;
use App\Entity\Configurator\FontColor;
use App\Entity\Configurator\Library;
use App\Entity\Configurator\Model;
use App\Entity\Configurator\Workflow;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Model\ElementType as types;
final class ElementType extends AbstractResourceType
{
public function buildView(FormView $view, FormInterface $form, array $options): void
{
parent::buildView($view, $form, $options);
$view->vars['model'] = $options['model'];
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'label' => 'app.ui.name',
'attr' => ['class' => "js-simple-configurator"]
])
->add('level', IntegerType::class, [
'label' => 'app.form.configurator.level',
'attr' => ['class' => 'element-level level']
])
->add('visibleOnConfigurator', CheckboxType::class, [
'label' => 'app.form.configurator.visible_configurator',
'attr' => ['class' => 'element-visible']
])
->add('visibleOnPrint', CheckboxType::class, [
'label' => 'app.form.configurator.visible_print',
'attr' => ['class' => 'element-visible']
])
->add('allowRotation', CheckboxType::class, [
'label' => 'app.form.configurator.allow_rotation',
'attr' => ['class' => 'element-allow-rotation']
])
->add('allowMovement', CheckboxType::class, [
'label' => 'app.form.configurator.allow_movement',
'attr' => ['class' => 'element-allow-movement']
])
->add('linkedToPrintZone', CheckboxType::class, [
'label' => 'app.form.configurator.linked_to_print_zone',
'help' => 'app.form.configurator.linked_to_print_zone_help',
'attr' => ['class' => 'element-linked-to-print-zone']
])
->add('mandatory', CheckboxType::class, [
'label' => 'app.form.configurator.mandatory',
'attr' => ['class' => 'element-mandatory']
])
->add('width', NumberType::class, [
'label' => 'app.form.configurator.width_px',
'attr' => ['class' => 'column element-width element-size', 'min' => 10]
])
->add('height', NumberType::class, [
'label' => 'app.form.configurator.height_px',
'attr' => ['class' => 'column element-height element-size', 'min' => 10]
])
->add('coordinatesX', NumberType::class, [
'label' => 'app.form.configurator.coordinatesX',
'attr' => ['class' => 'column element-coordinates-x']
])
->add('coordinatesY', NumberType::class, [
'label' => 'app.form.configurator.coordinatesY',
'attr' => ['class' => 'column element-coordinates-y']
])
->add('orientation', IntegerType::class, [
'label' => 'app.form.configurator.orientation',
'attr' => ['class' => 'element-orientation']
])
->add('blended', CheckboxType::class, [
'label' => 'app.form.configurator.blended',
'required' => false
])
->add('type', ChoiceType::class, [
'label' => 'app.form.configurator.type',
'choices' => [
'app.form.configurator.image_admin' => types::TYPE_IMAGE_ADMIN,
'app.form.configurator.image_library' => types::TYPE_IMAGE_LIBRARY,
'app.form.configurator.image_upload' => types::TYPE_IMAGE_UPLOAD,
'app.form.configurator.text' => types::TYPE_TEXT,
'app.form.configurator.image_upload_or_library' => types::TYPE_IMAGE_UPLOAD_OR_LIBRARY,
'app.form.configurator.image_upload_or_bank' => types::TYPE_IMAGE_UPLOAD_OR_BANK,
'app.form.configurator.image_upload_or_library_or_bank' => types::TYPE_IMAGE_UPLOAD_OR_LIBRARY_OR_BANK,
'app.form.configurator.image_bank_or_generation' => types::TYPE_IMAGE_BANK_OR_GENERATION,
],
'attr' => ['class' => "js-input-type element-type js-simple-configurator"]
])
->add('libraries', LibraryAutocompleteChoiceType::class, [
'placeholder' => 'app.form.configurator.choose_a_library',
'required' => false,
'multiple' => true,
'label' => 'app.form.configurator.libraries'
])
->add('file', FileType::class, [
'attr' => ['class' => 'js-field-type js-type-image'],
'label' => 'sylius.form.image.file'
])
->add('defaultText', TextareaType::class, [
'attr' => ['class' => 'js-field-type js-type-text js-text-default-text js-simple-configurator'],
'label' => 'app.form.configurator.default_text',
'required' => false
])
->add('curvedText', CheckboxType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-text-curved'],
'label' => 'app.form.configurator.allow_curved_text',
'required' => false
])
->add('defaultTextSize', IntegerType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-default-text-size', 'min' => 5],
'label' => 'app.form.configurator.default_text_size',
'required' => false
])
->add('linesMax', IntegerType::class, [
'label' => 'app.form.configurator.line_max',
'attr' => ['class' => 'element-line-max js-field-type js-type-text', 'min' => 1]
])
->add('characterLimit', IntegerType::class, [
'label' => 'app.form.configurator.character_limit',
'attr' => ['class' => 'element-character-limit js-field-type js-type-text js-simple-configurator'],
'required' => false
])
->add('textSizeMin', IntegerType::class, [
'label' => 'app.form.configurator.text_size_min',
'attr' => ['class' => 'element-text-size-min js-field-type js-type-text js-simple-configurator'],
'required' => false
])
->add('allowLineSpaceChange', CheckboxType::class, [
'label' => 'app.form.configurator.allow_line_space_change',
'attr' => ['class' => 'element-allow-line-space-change js-field-type js-type-text'],
'required' => false
])
->add('lineSpace', NumberType::class, [
'label' => 'app.form.configurator.line_space',
'attr' => ['class' => 'element-line-space js-field-type js-type-text'],
'required' => false
])
->add('textBold', CheckboxType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-text-bold'],
'label' => 'app.form.configurator.text_bold',
'required' => false
])
->add('textItalic', CheckboxType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-text-italic'],
'label' => 'app.form.configurator.text_italic',
'required' => false
])
->add('textAlignment', ChoiceType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-text-aligment'],
'label' => 'app.form.configurator.text_alignment',
'choices' => [
'center' => 'center',
'left' => 'left',
'right' => 'right',
],
])
->add('fonts', FontAutoCompleteChoiceType::class, [
'label' => 'app.form.configurator.fonts',
'required' => false,
'multiple' => true,
'placeholder' => "app.form.configurator.fonts"
])
->add('defaultFont', EntityType::class, [
'class' => Font::class,
'required' => false,
'label' => "app.form.configurator.default_font",
'choice_label' => 'name',
'choice_attr' => function ($entity) {
return ['data-file-path' => $entity->getFilePath()];
},
'attr' => ['class' => 'js-field-type js-type-text default-font'],
'placeholder' => 'app.form.configurator.choose_font'
])
->add('fontColors', FontColorAutoCompleteChoiceType::class, [
'label' => 'app.form.configurator.font_colors',
'required' => false,
'multiple' => true,
'placeholder' => "app.form.configurator.font_colors"
])
->add('strokeColors', FontColorAutoCompleteChoiceType::class, [
'label' => 'app.form.configurator.stroke_colors',
'required' => false,
'multiple' => true,
'placeholder' => "app.form.configurator.stroke_colors"
])
->add('shadowColors', FontColorAutoCompleteChoiceType::class, [
'label' => 'app.form.configurator.shadow_colors',
'required' => false,
'multiple' => true,
'placeholder' => "app.form.configurator.shadow_colors"
])
->add('defaultFontColor', EntityType::class, [
'class' => FontColor::class,
'label' => 'app.form.configurator.default_font_color',
'required' => false,
'choice_label' => function ($entity) {
return $entity->getTranslation()->getMetaTitle();
},
'choice_attr' => function ($entity) {
return ['data-color' => $entity->getHexadecimal()];
},
'attr' => ['class' => 'js-field-type js-type-text default-font-color'],
'placeholder' => 'app.form.configurator.choose_font_color'
])
->add('defaultStrokeColor', EntityType::class, [
'placeholder' => 'app.form.configurator.no_stroke_color',
'class' => FontColor::class,
'label' => 'app.form.configurator.default_stroke_color',
'required' => false,
'choice_label' => function ($entity) {
return $entity->getTranslation()->getMetaTitle();
},
'choice_attr' => function ($entity) {
return ['data-color' => $entity->getHexadecimal()];
},
'attr' => ['class' => 'js-field-type js-type-text default-stroke-color']
])
->add('defaultShadowColor', EntityType::class, [
'class' => FontColor::class,
'label' => 'app.form.configurator.default_shadow_color',
'required' => false,
'choice_label' => function ($entity) {
return $entity->getTranslation()->getMetaTitle();
},
'choice_attr' => function ($entity) {
return ['data-color' => $entity->getHexadecimal()];
},
'attr' => ['class' => 'js-field-type js-type-text default-shadow-color'],
'placeholder' => 'app.form.configurator.no_shadow_color'
])
->add('forcePrintColor', CheckboxType::class, [
'attr' => ['class' => 'js-field-type js-type-text element-force-print-color'],
'label' => 'app.form.configurator.has_print_color',
'help' => 'app.form.configurator.has_print_color_help',
'required' => false
])
->add('printColor', ColorType::class, [
'label' => 'app.form.configurator.color',
'attr' => ['class' => 'js-field-type js-type-text'],
'required' => false
])
->add('defaultLibrary', EntityType::class, [
'label' => 'app.form.configurator.default_library',
'class' => Library::class,
'required' => false,
'choice_label' => function ($entity) {
return $entity->getTranslation()->getName();
},
'choice_attr' => function ($entity) {
if(count($entity->getFiles()) > 0 ){
return ['data-first-image' => $entity->getFiles()->first()->getPath()];
}
else {
return [];
}
},
'attr' => ['class' => 'js-field-type js-type-library default-library'],
'placeholder' => 'app.form.configurator.choose_a_default_library'
])
->add('diameter', TextType::class, [
'label' => 'app.form.configurator.diameter',
'required' => false,
'attr' => ['class' => 'js-field-type js-type-text element-diameter'],
])
->add('workflow', EntityType::class, [
'class' => Workflow::class,
'required' => false,
'label' => "app.form.configurator.associated_workflow",
'choice_label' => 'name',
'choice_attr' => function ($entity) {
return ['data-file-path' => $entity->getFilePath()];
},
'attr' => ['class' => 'js-field-type js-type-image-upload default-workflow'],
'placeholder' => 'app.form.configurator.choose_workflow'
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->setDefined('model');
$resolver->setAllowedTypes('model', Model::class);
}
public function getBlockPrefix(): string
{
return 'app_configurator_element';
}
}