<?php
namespace App\Form\Type;
use App\Entity\Country;
use Symfony\Component\Form\AbstractType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CountryType extends AbstractType
{
/**
* @var EntityManagerInterface
*/
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function configureOptions(OptionsResolver $resolver)
{
$typeNotification = $this->em->getRepository(Country::class);
$choices = [];
foreach ($typeNotification->findAll() as $type) {
$label = $type->getName();
$choices[$label] = $type->getId();
}
$resolver->setDefaults([
'choices' => $choices,
]);
}
public function getParent()
{
return ChoiceType::class;
}
}