src/Form/Choice/CountryChoiceType.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\Choice;
  4. use App\Entity\Channel\CountryPricesInterface;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Intl\Countries;
  8. use Symfony\Component\OptionsResolver\Options;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. final class CountryChoiceType extends AbstractType
  11. {
  12.     public function configureOptions(OptionsResolver $resolver): void
  13.     {
  14.         $resolver->setDefaults([
  15.             'choices' => static function (Options $options) {
  16.                 $choices = [];
  17.                 foreach (CountryPricesInterface::ALL as $countryCode => $price) {
  18.                     $choices[Countries::getName($countryCode)] = $countryCode;
  19.                 }
  20.                 return $choices;
  21.             },
  22.             'choice_translation_domain' => false,
  23.         ]);
  24.     }
  25.     public function getParent(): string
  26.     {
  27.         return ChoiceType::class;
  28.     }
  29.     public function getBlockPrefix(): string
  30.     {
  31.         return 'country';
  32.     }
  33. }