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\ThirdPartyProfession;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -57,55 +58,16 @@ class ThirdPartyType extends AbstractType
}
$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, [
'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, [
'label' => 'thirdparty.Categories',
'class' => ThirdPartyCategory::class,
'choice_label' => function (ThirdPartyCategory $category) {
'choice_label' => function (ThirdPartyCategory $category): string {
return $this->translatableStringHelper->localize($category->getName());
},
'query_builder' => function (EntityRepository $er) {
'query_builder' => function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
@ -113,29 +75,24 @@ class ThirdPartyType extends AbstractType
'multiple' => true,
'attr' => ['class' => 'select2']
])
->add('type', ChoiceType::class, [
'choices' => $types,
'expanded' => true,
'multiple' => true,
'label' => 'thirdparty.Type'
])
->add('telephone', TextType::class, [
'label' => 'Phonenumber',
'required' => false
])
->add('email', EmailType::class, [
'required' => false
])
->add('address', AddressType::class, [
'has_valid_from' => false,
'null_if_empty' => true,
'required' => false
])
->add('active', ChoiceType::class, [
'label' => 'thirdparty.Status',
'choices' => [
@ -145,11 +102,9 @@ class ThirdPartyType extends AbstractType
'expanded' => true,
'multiple' => false
])
->add('comment', ChillTextareaType::class, [
'required' => false
])
->add('centers', EntityType::class, [
'choices' => $this->getReachableCenters($options),
'class' => \Chill\MainBundle\Entity\Center::class,
@ -157,6 +112,51 @@ class ThirdPartyType extends AbstractType
'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) }}
{% if thirdParty.isLeaf == true %}
{% if form.civility is defined %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %}
{% if form.nameCompany is defined %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if thirdParty.isLeaf == true %}
{% if form.profession is defined %}
{{ form_row(form.profession) }}
{% endif %}

View File

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