Features/new phones

This commit is contained in:
Jean-Francois Monfort
2021-04-02 12:11:20 +00:00
committed by Julien Fastré
parent 6ea45e4d16
commit 27c680bb03
14 changed files with 502 additions and 123 deletions

View File

@@ -21,21 +21,24 @@
namespace Chill\PersonBundle\Form;
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
use Chill\MainBundle\Form\Type\ChillCollectionType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\Select2CountryType;
use Chill\MainBundle\Form\Type\Select2LanguageType;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
use Chill\PersonBundle\Form\Type\PersonPhoneType;
use Chill\PersonBundle\Entity\PersonPhone;
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\Select2CountryType;
use Chill\MainBundle\Form\Type\Select2LanguageType;
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PersonType extends AbstractType
{
@@ -48,7 +51,7 @@ class PersonType extends AbstractType
* @var string[]
*/
protected $config = array();
/**
*
* @var ConfigPersonAltNamesHelper
@@ -80,13 +83,13 @@ class PersonType extends AbstractType
->add('gender', GenderType::class, array(
'required' => true
));
if ($this->configAltNamesHelper->hasAltNames()) {
$builder->add('altNames', PersonAltNameType::class, [
'by_reference' => false
]);
}
if ($this->config['memo'] === 'visible') {
$builder
->add('memo', ChillTextareaType::class, array('required' => false))
@@ -104,11 +107,25 @@ class PersonType extends AbstractType
if ($this->config['phonenumber'] === 'visible') {
$builder->add('phonenumber', TelType::class, array('required' => false));
}
if ($this->config['mobilenumber'] === 'visible') {
$builder->add('mobilenumber', TelType::class, array('required' => false));
}
$builder->add('otherPhoneNumbers', ChillCollectionType::class, [
'entry_type' => PersonPhoneType::class,
'button_add_label' => 'Add new phone',
'button_remove_label' => 'Remove phone',
'required' => false,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => false,
'delete_empty' => function(PersonPhone $pp = null) {
return NULL === $pp || $pp->isEmpty();
}
]);
if ($this->config['email'] === 'visible') {
$builder->add('email', EmailType::class, array('required' => false));
}
@@ -153,7 +170,7 @@ class PersonType extends AbstractType
{
$resolver->setDefaults(array(
'data_class' => 'Chill\PersonBundle\Entity\Person',
'validation_groups' => array('general', 'creation')
'validation_groups' => array('general', 'creation'),
));
$resolver->setRequired(array(

View File

@@ -0,0 +1,65 @@
<?php
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;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PersonPhoneType extends AbstractType
{
private 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)
{
$builder->add('phonenumber', TelType::class, [
'label' => 'Other phonenumber',
'required' => true,
]);
$builder->add('description', TextType::class, [
'required' => false,
]);
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
if (NULL === $event->getData()) {
return;
}
$oldPersonPhone = $this->em->getUnitOfWork()
->getOriginalEntityData($event->getData());
if ($oldPersonPhone['phonenumber'] ?? null !== $event->getForm()->getData()->getPhonenumber()) {
$type = $this->phonenumberHelper->getType($event->getData()->getPhonenumber());
$event->getData()->setType($type);
}
});
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'data_class' => PersonPhone::class,
'validation_groups' => ['general', 'creation'],
])
;
}
}