mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
thirdparty, manage case with only one type
in that case, type field is hidden, uniq type is automatically written in table
This commit is contained in:
parent
6e31e01e51
commit
683eac91d8
@ -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)
|
||||
|
@ -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) }}
|
||||
|
@ -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) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user