<?php

namespace App\Form\Type;

use App\Entity\VenteEmlcAdherent;
use App\Entity\Adherent;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class VenteEmlcAdherentFormType extends VenteEmlcFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if (empty($this->security) || empty($this->security->getUser())) {
            throw new \Exception("[FORM VENTE EMLC ADHERENT] Opération impossible !");
        }
        $builder
            ->add('destinataire', EntityType::class, array(
                'class' => Adherent::class,
                'choices' =>  $this->em->getRepository(Adherent::class)->findOrderByName(),
                'placeholder' => 'Adherent',
                'required' => true,
                'label' => 'Adherent :',
            ))
            ->add('reference', HiddenType::class, array(
                'data' => 'Achat eMLC Adhérent'
            ))
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'class' => VenteEmlcComptoirAdherent::class,
        ));
    }

    public function getParent()
    {
        return VenteEmlcFormType::class;
    }

    public function getBlockPrefix()
    {
        return 'formVenteEmlcAdherent';
    }
}
