mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Features/new phones
This commit is contained in:
@@ -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(
|
||||
|
65
src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php
Normal file
65
src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php
Normal 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'],
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user