<?php
namespace App\Form;
use App\Component\Configuration\Util\Config;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType as MisdPhoneNumberType;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as PhoneNumberConstraint;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PhoneNumberType extends AbstractType
{
/**
* PhoneNumberType Constructor.
*/
public function __construct(
private readonly Config $config,
) {
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
if ($this->config->get('phone_use_country_select_widget')) {
$resolver->setDefaults([
'preferred_country_choices' => [$this->config->get('site_default_phone_country'), ...$this->config->get('site_preferred_phone_countries')],
'default_region' => $this->config->get('site_default_phone_country'),
'widget' => MisdPhoneNumberType::WIDGET_COUNTRY_CHOICE,
'attr' => [
'class' => 'localized-phone-number',
],
'country_choices' => $this->config->get('site_phone_country_choices'),
]);
}
$resolver->setDefaults([
'html5' => true,
'constraints' => [new PhoneNumberConstraint()],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
if ($this->config->get('phone_use_country_select_widget')) {
return TelCountrySelectType::class;
}
return TelType::class;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
if ($this->config->get('phone_use_country_select_widget')) {
return 'country_select';
}
return 'phone';
}
}