diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index 3248e7ff0..9db5013c3 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -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 + ]) + ; + } } /** diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig index 72e4c9ad4..1997466c2 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig @@ -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 %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig index fe756cc51..85c8dd41d 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig @@ -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 %}