src/Form/Type/Admin/ElementType.php line 220

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\Type\Admin;
  4. use App\Entity\Configurator\Font;
  5. use App\Entity\Configurator\FontColor;
  6. use App\Entity\Configurator\Library;
  7. use App\Entity\Configurator\Model;
  8. use App\Entity\Configurator\Workflow;
  9. use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
  10. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  11. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. use Symfony\Component\Form\Extension\Core\Type\ColorType;
  14. use Symfony\Component\Form\Extension\Core\Type\FileType;
  15. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  16. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextType;
  19. use Symfony\Component\Form\FormBuilderInterface;
  20. use Symfony\Component\Form\FormInterface;
  21. use Symfony\Component\Form\FormView;
  22. use Symfony\Component\OptionsResolver\OptionsResolver;
  23. use App\Model\ElementType as types;
  24. final class ElementType extends AbstractResourceType
  25. {
  26.     public function buildView(FormView $viewFormInterface $form, array $options): void
  27.     {
  28.         parent::buildView($view$form$options);
  29.         $view->vars['model'] = $options['model'];
  30.     }
  31.     public function buildForm(FormBuilderInterface $builder, array $options): void
  32.     {
  33.         $builder
  34.             ->add('name'TextType::class, [
  35.                 'label' => 'app.ui.name',
  36.                 'attr' => ['class' => "js-simple-configurator"]
  37.             ])
  38.             ->add('level'IntegerType::class, [
  39.                 'label' => 'app.form.configurator.level',
  40.                 'attr' => ['class' => 'element-level level']
  41.             ])
  42.             ->add('visibleOnConfigurator'CheckboxType::class, [
  43.                 'label' => 'app.form.configurator.visible_configurator',
  44.                 'attr' => ['class' => 'element-visible']
  45.             ])
  46.             ->add('visibleOnPrint'CheckboxType::class, [
  47.                 'label' => 'app.form.configurator.visible_print',
  48.                 'attr' => ['class' => 'element-visible']
  49.             ])
  50.             ->add('allowRotation'CheckboxType::class, [
  51.                 'label' => 'app.form.configurator.allow_rotation',
  52.                 'attr' => ['class' => 'element-allow-rotation']
  53.             ])
  54.             ->add('allowMovement'CheckboxType::class, [
  55.                 'label' => 'app.form.configurator.allow_movement',
  56.                 'attr' => ['class' => 'element-allow-movement']
  57.             ])
  58.             ->add('linkedToPrintZone'CheckboxType::class, [
  59.                 'label' => 'app.form.configurator.linked_to_print_zone',
  60.                 'help' => 'app.form.configurator.linked_to_print_zone_help',
  61.                 'attr' => ['class' => 'element-linked-to-print-zone']
  62.             ])
  63.             ->add('mandatory'CheckboxType::class, [
  64.                 'label' => 'app.form.configurator.mandatory',
  65.                 'attr' => ['class' => 'element-mandatory']
  66.             ])
  67.             ->add('width'NumberType::class, [
  68.                 'label' => 'app.form.configurator.width_px',
  69.                 'attr' => ['class' => 'column element-width element-size''min' => 10]
  70.             ])
  71.             ->add('height'NumberType::class, [
  72.                 'label' => 'app.form.configurator.height_px',
  73.                 'attr' => ['class' => 'column element-height element-size''min' => 10]
  74.             ])
  75.             ->add('coordinatesX'NumberType::class, [
  76.                 'label' => 'app.form.configurator.coordinatesX',
  77.                 'attr' => ['class' => 'column element-coordinates-x']
  78.             ])
  79.             ->add('coordinatesY'NumberType::class, [
  80.                 'label' => 'app.form.configurator.coordinatesY',
  81.                 'attr' => ['class' => 'column element-coordinates-y']
  82.             ])
  83.             ->add('orientation'IntegerType::class, [
  84.                 'label' => 'app.form.configurator.orientation',
  85.                 'attr' => ['class' => 'element-orientation']
  86.             ])
  87.             ->add('blended'CheckboxType::class, [
  88.                 'label' => 'app.form.configurator.blended',
  89.                 'required' => false
  90.             ])
  91.             ->add('type'ChoiceType::class, [
  92.                 'label' => 'app.form.configurator.type',
  93.                 'choices' => [
  94.                     'app.form.configurator.image_admin' => types::TYPE_IMAGE_ADMIN,
  95.                     'app.form.configurator.image_library' => types::TYPE_IMAGE_LIBRARY,
  96.                     'app.form.configurator.image_upload' => types::TYPE_IMAGE_UPLOAD,
  97.                     'app.form.configurator.text' => types::TYPE_TEXT,
  98.                     'app.form.configurator.image_upload_or_library' => types::TYPE_IMAGE_UPLOAD_OR_LIBRARY,
  99.                     'app.form.configurator.image_upload_or_bank' => types::TYPE_IMAGE_UPLOAD_OR_BANK,
  100.                     'app.form.configurator.image_upload_or_library_or_bank' => types::TYPE_IMAGE_UPLOAD_OR_LIBRARY_OR_BANK,
  101.                     'app.form.configurator.image_bank_or_generation' => types::TYPE_IMAGE_BANK_OR_GENERATION,
  102.                 ],
  103.                 'attr' => ['class' => "js-input-type element-type js-simple-configurator"]
  104.             ])
  105.             ->add('libraries'LibraryAutocompleteChoiceType::class, [
  106.                 'placeholder' => 'app.form.configurator.choose_a_library',
  107.                 'required' => false,
  108.                 'multiple' => true,
  109.                 'label' => 'app.form.configurator.libraries'
  110.             ])
  111.             ->add('file'FileType::class, [
  112.                 'attr' => ['class' => 'js-field-type js-type-image'],
  113.                 'label' => 'sylius.form.image.file'
  114.             ])
  115.             ->add('defaultText'TextareaType::class, [
  116.                 'attr' => ['class' => 'js-field-type js-type-text js-text-default-text js-simple-configurator'],
  117.                 'label' => 'app.form.configurator.default_text',
  118.                 'required' => false
  119.             ])
  120.             ->add('curvedText'CheckboxType::class, [
  121.                 'attr' => ['class' => 'js-field-type js-type-text element-text-curved'],
  122.                 'label' => 'app.form.configurator.allow_curved_text',
  123.                 'required' => false
  124.             ])
  125.             ->add('defaultTextSize'IntegerType::class, [
  126.                 'attr' => ['class' => 'js-field-type js-type-text element-default-text-size''min' => 5],
  127.                 'label' => 'app.form.configurator.default_text_size',
  128.                 'required' => false
  129.             ])
  130.             ->add('linesMax'IntegerType::class, [
  131.                 'label' => 'app.form.configurator.line_max',
  132.                 'attr' => ['class' => 'element-line-max js-field-type js-type-text''min' => 1]
  133.             ])
  134.             ->add('characterLimit'IntegerType::class, [
  135.                 'label' => 'app.form.configurator.character_limit',
  136.                 'attr' => ['class' => 'element-character-limit js-field-type js-type-text js-simple-configurator'],
  137.                 'required' => false
  138.             ])
  139.             ->add('textSizeMin'IntegerType::class, [
  140.                 'label' => 'app.form.configurator.text_size_min',
  141.                 'attr' => ['class' => 'element-text-size-min js-field-type js-type-text js-simple-configurator'],
  142.                 'required' => false
  143.             ])
  144.             ->add('allowLineSpaceChange'CheckboxType::class, [
  145.                 'label' => 'app.form.configurator.allow_line_space_change',
  146.                 'attr' => ['class' => 'element-allow-line-space-change js-field-type js-type-text'],
  147.                 'required' => false
  148.             ])
  149.             ->add('lineSpace'NumberType::class, [
  150.                 'label' => 'app.form.configurator.line_space',
  151.                 'attr' => ['class' => 'element-line-space js-field-type js-type-text'],
  152.                 'required' => false
  153.             ])
  154.             ->add('textBold'CheckboxType::class, [
  155.                 'attr' => ['class' => 'js-field-type js-type-text element-text-bold'],
  156.                 'label' => 'app.form.configurator.text_bold',
  157.                 'required' => false
  158.             ])
  159.             ->add('textItalic'CheckboxType::class, [
  160.                 'attr' => ['class' => 'js-field-type js-type-text element-text-italic'],
  161.                 'label' => 'app.form.configurator.text_italic',
  162.                 'required' => false
  163.             ])
  164.             ->add('textAlignment'ChoiceType::class, [
  165.                 'attr' => ['class' => 'js-field-type js-type-text element-text-aligment'],
  166.                 'label' => 'app.form.configurator.text_alignment',
  167.                 'choices' => [
  168.                     'center' => 'center',
  169.                     'left' => 'left',
  170.                     'right' => 'right',
  171.                 ],
  172.             ])
  173.             ->add('fonts'FontAutoCompleteChoiceType::class, [
  174.                 'label' => 'app.form.configurator.fonts',
  175.                 'required' => false,
  176.                 'multiple' => true,
  177.                 'placeholder' => "app.form.configurator.fonts"
  178.             ])
  179.             ->add('defaultFont'EntityType::class, [
  180.                 'class' => Font::class,
  181.                 'required' => false,
  182.                 'label' => "app.form.configurator.default_font",
  183.                 'choice_label' => 'name',
  184.                 'choice_attr' => function ($entity) {
  185.                     return ['data-file-path' => $entity->getFilePath()];
  186.                 },
  187.                 'attr' => ['class' => 'js-field-type js-type-text default-font'],
  188.                 'placeholder' => 'app.form.configurator.choose_font'
  189.             ])
  190.             ->add('fontColors'FontColorAutoCompleteChoiceType::class, [
  191.                 'label' => 'app.form.configurator.font_colors',
  192.                 'required' => false,
  193.                 'multiple' => true,
  194.                 'placeholder' => "app.form.configurator.font_colors"
  195.             ])
  196.             ->add('strokeColors'FontColorAutoCompleteChoiceType::class, [
  197.                 'label' => 'app.form.configurator.stroke_colors',
  198.                 'required' => false,
  199.                 'multiple' => true,
  200.                 'placeholder' => "app.form.configurator.stroke_colors"
  201.             ])
  202.             ->add('shadowColors'FontColorAutoCompleteChoiceType::class, [
  203.                 'label' => 'app.form.configurator.shadow_colors',
  204.                 'required' => false,
  205.                 'multiple' => true,
  206.                 'placeholder' => "app.form.configurator.shadow_colors"
  207.             ])
  208.             ->add('defaultFontColor'EntityType::class, [
  209.                 'class' => FontColor::class,
  210.                 'label' => 'app.form.configurator.default_font_color',
  211.                 'required' => false,
  212.                 'choice_label' => function ($entity) {
  213.                     return $entity->getTranslation()->getMetaTitle();
  214.                 },
  215.                 'choice_attr' => function ($entity) {
  216.                     return ['data-color' => $entity->getHexadecimal()];
  217.                 },
  218.                 'attr' => ['class' => 'js-field-type js-type-text default-font-color'],
  219.                 'placeholder' => 'app.form.configurator.choose_font_color'
  220.             ])
  221.             ->add('defaultStrokeColor'EntityType::class, [
  222.                 'placeholder' => 'app.form.configurator.no_stroke_color',
  223.                 'class' => FontColor::class,
  224.                 'label' => 'app.form.configurator.default_stroke_color',
  225.                 'required' => false,
  226.                 'choice_label' => function ($entity) {
  227.                     return $entity->getTranslation()->getMetaTitle();
  228.                 },
  229.                 'choice_attr' => function ($entity) {
  230.                     return ['data-color' => $entity->getHexadecimal()];
  231.                 },
  232.                 'attr' => ['class' => 'js-field-type js-type-text default-stroke-color']
  233.             ])
  234.             ->add('defaultShadowColor'EntityType::class, [
  235.                 'class' => FontColor::class,
  236.                 'label' => 'app.form.configurator.default_shadow_color',
  237.                 'required' => false,
  238.                 'choice_label' => function ($entity) {
  239.                     return $entity->getTranslation()->getMetaTitle();
  240.                 },
  241.                 'choice_attr' => function ($entity) {
  242.                     return ['data-color' => $entity->getHexadecimal()];
  243.                 },
  244.                 'attr' => ['class' => 'js-field-type js-type-text default-shadow-color'],
  245.                 'placeholder' => 'app.form.configurator.no_shadow_color'
  246.             ])
  247.             ->add('forcePrintColor'CheckboxType::class, [
  248.                 'attr' => ['class' => 'js-field-type js-type-text element-force-print-color'],
  249.                 'label' => 'app.form.configurator.has_print_color',
  250.                 'help' => 'app.form.configurator.has_print_color_help',
  251.                 'required' => false
  252.             ])
  253.             ->add('printColor'ColorType::class, [
  254.                 'label' => 'app.form.configurator.color',
  255.                 'attr' => ['class' => 'js-field-type js-type-text'],
  256.                 'required' => false
  257.             ])
  258.             ->add('defaultLibrary'EntityType::class, [
  259.                 'label' => 'app.form.configurator.default_library',
  260.                 'class' => Library::class,
  261.                 'required' => false,
  262.                 'choice_label' => function ($entity) {
  263.                     return $entity->getTranslation()->getName();
  264.                 },
  265.                 'choice_attr' => function ($entity) {
  266.                     if(count($entity->getFiles()) > ){
  267.                         return ['data-first-image' => $entity->getFiles()->first()->getPath()];
  268.                     }
  269.                     else {
  270.                         return [];
  271.                     }
  272.                 },
  273.                 'attr' => ['class' => 'js-field-type js-type-library default-library'],
  274.                 'placeholder' => 'app.form.configurator.choose_a_default_library'
  275.             ])
  276.             ->add('diameter'TextType::class, [
  277.                 'label' => 'app.form.configurator.diameter',
  278.                 'required' => false,
  279.                 'attr' => ['class' => 'js-field-type js-type-text element-diameter'],
  280.             ])
  281.             ->add('workflow'EntityType::class, [
  282.                 'class' => Workflow::class,
  283.                 'required' => false,
  284.                 'label' => "app.form.configurator.associated_workflow",
  285.                 'choice_label' => 'name',
  286.                 'choice_attr' => function ($entity) {
  287.                     return ['data-file-path' => $entity->getFilePath()];
  288.                 },
  289.                 'attr' => ['class' => 'js-field-type js-type-image-upload default-workflow'],
  290.                 'placeholder' => 'app.form.configurator.choose_workflow'
  291.             ])
  292.         ;
  293.     }
  294.     public function configureOptions(OptionsResolver $resolver): void
  295.     {
  296.         parent::configureOptions($resolver);
  297.         $resolver->setDefined('model');
  298.         $resolver->setAllowedTypes('model'Model::class);
  299.     }
  300.     public function getBlockPrefix(): string
  301.     {
  302.         return 'app_configurator_element';
  303.     }
  304. }