mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
Add other phone number
This commit is contained in:
parent
756ed616b6
commit
068b269af9
@ -141,7 +141,14 @@ class PhonenumberHelper
|
||||
return \in_array($validation, [ 'landline', 'voip', 'mobile' ]);
|
||||
}
|
||||
|
||||
public function type(string $phonenumber): string
|
||||
/**
|
||||
* Get type (mobile, landline, ...) for phone number
|
||||
*
|
||||
* @param string $phonenumber
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(string $phonenumber): string
|
||||
{
|
||||
return $this->performTwilioLookup($phonenumber);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
@ -18,9 +19,12 @@ class PersonPhoneType extends AbstractType
|
||||
{
|
||||
private PhonenumberHelper $phonenumberHelper;
|
||||
|
||||
public function __construct(PhonenumberHelper $phonenumberHelper)
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(PhonenumberHelper $phonenumberHelper, EntityManagerInterface $em)
|
||||
{
|
||||
$this->phonenumberHelper = $phonenumberHelper;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
@ -35,8 +39,13 @@ class PersonPhoneType extends AbstractType
|
||||
]);
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
|
||||
$type = $this->phonenumberHelper->type($event->getData()->getPhonenumber());
|
||||
$oldPersonPhone = $this->em->getUnitOfWork()
|
||||
->getOriginalEntityData($event->getData());
|
||||
|
||||
if ($oldPersonPhone['phonenumber'] !== $event->getForm()->getData()->getPhonenumber()) {
|
||||
$type = $this->phonenumberHelper->getType($event->getData()->getPhonenumber());
|
||||
$event->getData()->setType($type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -50,5 +50,6 @@ services:
|
||||
Chill\PersonBundle\Form\Type\PersonPhoneType:
|
||||
arguments:
|
||||
$phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper'
|
||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||
tags:
|
||||
- { name: form.type }
|
||||
|
Loading…
x
Reference in New Issue
Block a user