src/Form/Type/SiteHome/SlideType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type\SiteHome;
  3. use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
  4. use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\FormEvent;
  11. use Symfony\Component\Form\FormEvents;
  12. use App\Entity\SiteHome\SlideImage;
  13. use App\Entity\Product\ProductVariant;
  14. use Symfony\Component\Form\Extension\Core\Type\DateType;
  15. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  16. class SlideType extends AbstractResourceType
  17. {
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function buildForm(FormBuilderInterface $builder, array $options)
  22.     {
  23.         $builder
  24.             ->add('translations'ResourceTranslationsType::class, [
  25.                 'entry_type' => SlideTranslationType::class,
  26.             ])
  27.             ->add('fabricProduct'EntityType::class, [
  28.                 'label' => 'Choisir un produit tissu',
  29.                 'class' => ProductVariant::class,
  30.                 'query_builder' => function ($er) {
  31.                     return $er->createQueryBuilder('o')
  32.                     ->innerJoin('o.translations''translation''WITH''translation.locale = :locale')
  33.                     ->andWhere('o.code LIKE :code')
  34.                     ->setParameter('locale''fr_FR')
  35.                     ->setParameter('code''TISS.%')
  36.                     ->orderBy('translation.name''ASC');
  37.                 },
  38.                 'choice_label' => 'name',
  39.                 'choice_value' => 'id',
  40.                 'required' => false,
  41.                 'multiple' => false
  42.             ])
  43.             ->add('position'IntegerType::class, [
  44.                 'label' => "sylius.ui.position",
  45.                 'required' => false,
  46.             ])
  47.             ->add('enabled'CheckboxType::class, [
  48.                 'label' => "sylius.ui.enabled",
  49.                 'required' => false,
  50.             ])
  51.             ->add('dateDiffusion'DateTimeType::class, [
  52.                 'label' => 'Date de diffusion',
  53.                 'widget' => 'single_text',
  54.                 'required' => true
  55.             ])
  56.             ->add('images'CollectionType::class, [
  57.                 'entry_type' => SlideImageType::class,
  58.                 'allow_add' => false,
  59.                 'allow_delete' => false,
  60.                 'by_reference' => false,
  61.                 'required' => true,
  62.                 'label' => 'Images'
  63.             ])
  64.             ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
  65.                 $data $event->getData();
  66.                 foreach (SlideImage::IMAGE_TYPES as $imageType) {
  67.                     if (count($data->getImagesByType($imageType)) <= 0) {
  68.                         $siteShopImage = new SlideImage();
  69.                         $siteShopImage->setType($imageType);
  70.                         $data->addImage($siteShopImage);
  71.                     }
  72.                 }
  73.             })
  74.         ;
  75.     }
  76.     /**
  77.      * {@inheritdoc}
  78.      */
  79.     public function getBlockPrefix()
  80.     {
  81.         return 'app_site_home_slide';
  82.     }
  83. }