diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index 30323794e..2ec113eb9 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -62,6 +62,35 @@ class ThirdPartyType extends AbstractType foreach ($this->typesManager->getProviders() as $key => $provider) { $types['chill_3party.key_label.'.$key] = $key; } + if (count($types) === 1) { + $builder + ->add('type', HiddenType::class, [ + 'data' => array_values($types) + ]) + ->get('type') + ->addModelTransformer(new CallbackTransformer( + function (?array $typeArray): ?string { + if (null === $typeArray) { + return null; + } + return implode(',', $typeArray); + }, + function (?string $typeStr): ?array { + if (null === $typeStr) { + return null; + } + return explode(',', $typeStr); + } + )) + ; + } else { + $builder->add('type', ChoiceType::class, [ + 'choices' => $types, + 'expanded' => true, + 'multiple' => true, + 'label' => 'thirdparty.Type' + ]); + } $builder ->add('name', TextType::class, [ @@ -81,12 +110,6 @@ 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 @@ -113,24 +136,26 @@ class ThirdPartyType extends AbstractType 'attr' => ['class' => 'select2'] ]) ; - $builder->add('address', HiddenType::class); - $builder->get('address') - ->addModelTransformer(new CallbackTransformer( - function (?Address $address): string { - if (null === $address) { - return ''; + + $builder + ->add('address', HiddenType::class) + ->get('address') + ->addModelTransformer(new CallbackTransformer( + function (?Address $address): string { + if (null === $address) { + return ''; + } + return $address->getId(); + }, + function (?string $addressId): ?Address { + if (null === $addressId) { + return null; + } + return $this->om + ->getRepository(Address::class) + ->findOneBy(['id' => (int) $addressId]); } - return $address->getId(); - }, - function (string $addressId): ?Address { - if ('' === $addressId) { - return null; - } - return $this->om - ->getRepository(Address::class) - ->findOneBy(['id' => (int) $addressId]); - } - )) + )) ; // Contact Person ThirdParty (child) diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig index fc0bb1a88..4fa9847c0 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig @@ -26,8 +26,8 @@ {{ form_row(form.profession) }} {% endif %} - {{ form_row(form.categories) }} {{ form_row(form.type) }} + {{ form_row(form.categories) }} {{ form_row(form.telephone) }} {{ form_row(form.email) }} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig index 768f4369e..340ecf15b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig @@ -43,8 +43,8 @@ {{ form_row(form.profession) }} {% endif %} - {{ form_row(form.categories) }} {{ form_row(form.type) }} + {{ form_row(form.categories) }} {{ form_row(form.telephone) }} {{ form_row(form.email) }}