GenderType is a child of ChoiceType. It is used to display a selection for social titles (genders) and comes pre-populated with the list of genders configured in PrestaShop.
PrestaShopBundle\Form\Admin\Sell\CustomerPrestaShopBundle\Form\Admin\Sell\Customer\GenderType| Option | Type | Default value | Description |
|---|---|---|---|
| choices | array | From provider | Automatically populated from GenderByIdChoiceProvider::getChoices(). |
| choice_translation_domain | boolean | false | Disables translation for choice labels (names come from database). |
| label | string | ‘Social title’ | Default label for the field. |
| translation_domain | string | ‘Admin.Global’ | Translation domain for the label. |
None.
<?php
// path/to/your/CustomType.php
use PrestaShopBundle\Form\Admin\Sell\Customer\GenderType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CustomType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('gender_id', GenderType::class, [
'expanded' => true,
'required' => false,
'placeholder' => null,
]);
}
}
When used with the expanded option set to true, the genders will be displayed as radio buttons:
<?php
$builder->add('gender_id', GenderType::class, [
'expanded' => true, // Display as radio buttons
'required' => false, // Make selection optional
'placeholder' => null, // No empty option
]);
Without the expanded option, genders display as a standard dropdown:
<?php
$builder->add('gender_id', GenderType::class);
GenderByIdChoiceProviderid_gender in the ps_gender tableps_gender_lang and displayed in the current language