src/Form/ExpensiveType.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Expensive;
  4. use App\Entity\Tiers;
  5. use App\Entity\categorieDepense;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use Doctrine\ORM\EntityRepository;
  13. class ExpensiveType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $boutique $options['boutique'];
  18.         $builder
  19.         
  20.             ->add('laDate',  DateType::class, [
  21.                 'widget' => 'single_text',
  22.                 'label' => 'admin.la_date',
  23.                  'attr' => [
  24.                 'class' => 'input-xs form-control',
  25.             ]])
  26.             ->add('piece',  null, [ 
  27.                 'label' => 'admin.expensives.piece',
  28.                  'attr' => [
  29.                 'class' => 'input-xs form-control',
  30.             ]])
  31.             ->add('tiers'EntityType::class, [
  32.                 'attr' => [
  33.                     'class' => 'form-control'
  34.                 ],
  35.                 // looks for choices from this entity
  36.                 'class' => Tiers::class,
  37.                 'label' => 'admin.third.label',
  38.                 'placeholder' =>'admin.third.choisir_un_tiers',
  39.                 
  40.                 
  41.                 'query_builder' => function (EntityRepository $er) use($boutique){
  42.                     return $er->createQueryBuilder('t')
  43.                         ->leftJoin ('t.boutique''b')
  44.                         ->addSelect('b')
  45.                         ->where('b.id =:boutique')
  46.                         ->setParameters(
  47.                             array('boutique' => $boutique)
  48.                         )
  49.                         ->orderBy('t.nom''ASC');
  50.         
  51.                     },
  52.                 // uses the User.username property as the visible option string
  53.                 'choice_label' => 'nom',
  54.                 // used to render a select box, check boxes or radios
  55.                 // 'multiple' => true,
  56.                 // 'expanded' => true,
  57.             ])
  58.              ->add('categorieDepense'EntityType::class, [
  59.                 'attr' => [
  60.                     'class' => 'form-control'
  61.                 ],
  62.                 // looks for choices from this entity
  63.                 'class' => CategorieDepense::class,
  64.                 'label' => 'admin.categorie_depense.categorie_depense_ou_poste_budgetaire',
  65.                 'placeholder' =>'admin.categorie_depense.categorie_depense',
  66.                 
  67.                 
  68.                 'query_builder' => function (EntityRepository $er) use($boutique){
  69.                     return $er->createQueryBuilder('t')
  70.                         ->leftJoin ('t.boutique''b')
  71.                         ->addSelect('b')
  72.                         ->where('b.id =:boutique')
  73.                         ->setParameters(
  74.                             array('boutique' => $boutique)
  75.                         )
  76.                         ->orderBy('t.nom''ASC');
  77.         
  78.                     },
  79.                 // uses the User.username property as the visible option string
  80.                 'choice_label' => 'nom',
  81.                 // used to render a select box, check boxes or radios
  82.                 // 'multiple' => true,
  83.                 // 'expanded' => true,
  84.             ])
  85.             ->add('montant'NumberType::class, ['label' => 'admin.expensives.montant''attr' => [
  86.                 'class' => 'form-control',
  87.                 'step' => '0.1'
  88.             ],
  89.             'html5' => true,
  90.         
  91.             ])
  92.             ->add('detail'null, ['label' => 'admin.detail''attr' => [
  93.                 'class' => 'form-control',
  94.             ]])
  95.         ;
  96.     }
  97.     public function configureOptions(OptionsResolver $resolver)
  98.     {
  99.         $resolver->setDefaults([
  100.             'data_class' => Expensive::class,
  101.             'boutique' => null
  102.         ]);
  103.     }
  104. }