src/Form/CartType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Cart;
  4. use App\Service\TwigGlobalVariables;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use App\Form\CartProductType;
  12. use App\Service\UserService;
  13. use App\Form\UserLocationType;
  14. use App\Entity\UserShippingLocation;
  15. use App\Entity\RecurringOrder;
  16. class CartType extends AbstractType
  17. {
  18.     public function __construct(UserService $userServTwigGlobalVariables $twigGlobalVariables){
  19.         $this->userServ $userServ;
  20.         $this->twigGlobalVariables $twigGlobalVariables;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         $userServ $this->userServ;
  25.         if($userServ->getUser())
  26.             $shipping $userServ->getUser()->getShippingAddresses();
  27.         else
  28.             $shipping null;
  29.         $builder
  30.             ->add('products'CollectionType::class, array(
  31.                     'entry_type' => CartProductType::class,
  32.                     'allow_delete' => true,
  33.                     'delete_empty' => true
  34.                 )
  35.             )
  36.             ->add('update'SubmitType::Class,
  37.                 array(
  38.                     'label' => 'Mise à jour du panier',
  39.                     'attr' => array(
  40.                         'class' => 'btn-secondary btn py-2 px-4 phone-fullwidth',
  41.                         'onclick' => 'document.getElementById(\'se-pre-con\').style.display=\'initial\';'
  42.                     )
  43.                 )
  44.             )
  45.             ->add('submit'SubmitType::Class,
  46.                 array(
  47.                     'label' => 'Passer à la Livraison / Cueillette',
  48.                     'attr' => array(
  49.                         'class' => 'btn-primary btn py-2 px-4 phone-fullwidth',
  50.                         'onclick' => 'document.getElementById(\'se-pre-con\').style.display=\'initial\';'
  51.                     )
  52.                 )
  53.             )
  54.         ;
  55.         if($userServ->getActiveRecurringOrders()){
  56.             $builder->add('recurring'EntityType::class, [
  57.                 'mapped' => false,
  58.                 'required' => false,
  59.                 'class' => RecurringOrder::class,
  60.                 'label' => 'Joindre a cette prochaine commande récurrente',
  61.                 'placeholder' => 'Choisir...',
  62.                 'query_builder' => function($er){
  63.                     return $er->findActiveOrdersOfUser(falsefalse);
  64.                 },
  65.                 'choice_label' => function($c){
  66.                     return (string)$c;
  67.                 }
  68.             ])
  69.             ;
  70.         }
  71.     }
  72.     public function configureOptions(OptionsResolver $resolver)
  73.     {
  74.         $resolver->setDefaults([
  75.             'data_class' => Cart::class,
  76.         ]);
  77.     }
  78. }