add isLeaf condition on ThirdParty form Type

This commit is contained in:
Mathieu Jaumotte 2021-07-22 16:34:07 +02:00
parent 587da94645
commit a559589883
3 changed files with 54 additions and 54 deletions

View File

@ -8,6 +8,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility; use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility;
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession; use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -57,55 +58,16 @@ class ThirdPartyType extends AbstractType
} }
$builder $builder
->add('civility', EntityType::class, [
'label' => 'thirdparty.Civility',
'class' => ThirdPartyCivility::class,
'choice_label' => function (ThirdPartyCivility $civility) {
return $this->translatableStringHelper->localize($civility->getName());
},
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'placeholder' => 'thirdparty.choose civility',
'required' => true
])
->add('name', TextType::class, [ ->add('name', TextType::class, [
'required' => true 'required' => true
]) ])
->add('nameCompany', TextType::class, [
'label' => 'thirdparty.NameCompany',
'required' => false
])
->add('profession', EntityType::class, [
'label' => 'thirdparty.Profession',
'class' => ThirdPartyProfession::class,
'choice_label' => function (ThirdPartyProfession $profession) {
return $this->translatableStringHelper->localize($profession->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->where('p.active = true');
},
'placeholder' => 'thirdparty.choose profession',
'required' => false
])
->add('acronym', TextType::class, [
'label' => 'thirdparty.Acronym',
'required' => false
])
->add('categories', EntityType::class, [ ->add('categories', EntityType::class, [
'label' => 'thirdparty.Categories', 'label' => 'thirdparty.Categories',
'class' => ThirdPartyCategory::class, 'class' => ThirdPartyCategory::class,
'choice_label' => function (ThirdPartyCategory $category) { 'choice_label' => function (ThirdPartyCategory $category): string {
return $this->translatableStringHelper->localize($category->getName()); return $this->translatableStringHelper->localize($category->getName());
}, },
'query_builder' => function (EntityRepository $er) { 'query_builder' => function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('c') return $er->createQueryBuilder('c')
->where('c.active = true'); ->where('c.active = true');
}, },
@ -113,29 +75,24 @@ class ThirdPartyType extends AbstractType
'multiple' => true, 'multiple' => true,
'attr' => ['class' => 'select2'] 'attr' => ['class' => 'select2']
]) ])
->add('type', ChoiceType::class, [ ->add('type', ChoiceType::class, [
'choices' => $types, 'choices' => $types,
'expanded' => true, 'expanded' => true,
'multiple' => true, 'multiple' => true,
'label' => 'thirdparty.Type' 'label' => 'thirdparty.Type'
]) ])
->add('telephone', TextType::class, [ ->add('telephone', TextType::class, [
'label' => 'Phonenumber', 'label' => 'Phonenumber',
'required' => false 'required' => false
]) ])
->add('email', EmailType::class, [ ->add('email', EmailType::class, [
'required' => false 'required' => false
]) ])
->add('address', AddressType::class, [ ->add('address', AddressType::class, [
'has_valid_from' => false, 'has_valid_from' => false,
'null_if_empty' => true, 'null_if_empty' => true,
'required' => false 'required' => false
]) ])
->add('active', ChoiceType::class, [ ->add('active', ChoiceType::class, [
'label' => 'thirdparty.Status', 'label' => 'thirdparty.Status',
'choices' => [ 'choices' => [
@ -145,11 +102,9 @@ class ThirdPartyType extends AbstractType
'expanded' => true, 'expanded' => true,
'multiple' => false 'multiple' => false
]) ])
->add('comment', ChillTextareaType::class, [ ->add('comment', ChillTextareaType::class, [
'required' => false 'required' => false
]) ])
->add('centers', EntityType::class, [ ->add('centers', EntityType::class, [
'choices' => $this->getReachableCenters($options), 'choices' => $this->getReachableCenters($options),
'class' => \Chill\MainBundle\Entity\Center::class, 'class' => \Chill\MainBundle\Entity\Center::class,
@ -157,6 +112,51 @@ class ThirdPartyType extends AbstractType
'attr' => ['class' => 'select2'] 'attr' => ['class' => 'select2']
]) ])
; ;
// Contact Person ThirdParty (child)
if ($options['data']->isLeaf()) {
$builder
->add('civility', EntityType::class, [
'label' => 'thirdparty.Civility',
'class' => ThirdPartyCivility::class,
'choice_label' => function (ThirdPartyCivility $civility): string {
return $this->translatableStringHelper->localize($civility->getName());
},
'query_builder' => function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'placeholder' => 'thirdparty.choose civility',
'required' => true
])
->add('profession', EntityType::class, [
'label' => 'thirdparty.Profession',
'class' => ThirdPartyProfession::class,
'choice_label' => function (ThirdPartyProfession $profession): string {
return $this->translatableStringHelper->localize($profession->getName());
},
'query_builder' => function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('p')
->where('p.active = true');
},
'placeholder' => 'thirdparty.choose profession',
'required' => false
])
;
// Institutional ThirdParty (parent)
} else {
$builder
->add('nameCompany', TextType::class, [
'label' => 'thirdparty.NameCompany',
'required' => false
])
->add('acronym', TextType::class, [
'label' => 'thirdparty.Acronym',
'required' => false
])
;
}
} }
/** /**

View File

@ -11,18 +11,18 @@
{{ form_start(form) }} {{ form_start(form) }}
{% if thirdParty.isLeaf == true %} {% if form.civility is defined %}
{{ form_row(form.civility) }} {{ form_row(form.civility) }}
{% endif %} {% endif %}
{{ form_row(form.name) }} {{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %} {% if form.nameCompany is defined %}
{{ form_row(form.nameCompany) }} {{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }} {{ form_row(form.acronym) }}
{% endif %} {% endif %}
{% if thirdParty.isLeaf == true %} {% if form.profession is defined %}
{{ form_row(form.profession) }} {{ form_row(form.profession) }}
{% endif %} {% endif %}

View File

@ -28,18 +28,18 @@
{{ form_start(form) }} {{ form_start(form) }}
{% if thirdParty.isLeaf == true %} {% if form.civility is defined %}
{{ form_row(form.civility) }} {{ form_row(form.civility) }}
{% endif %} {% endif %}
{{ form_row(form.name) }} {{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %} {% if form.nameCompany is defined %}
{{ form_row(form.nameCompany) }} {{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }} {{ form_row(form.acronym) }}
{% endif %} {% endif %}
{% if thirdParty.isLeaf == true %} {% if form.profession is defined %}
{{ form_row(form.profession) }} {{ form_row(form.profession) }}
{% endif %} {% endif %}