mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 15:25:00 +00:00
[address] allow to add custom data on addresses
This commit is contained in:
@@ -39,6 +39,8 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
* - `null_if_empty` (boolean): replace the address type by null if the street
|
||||
* or the postCode is empty. This is useful when the address is not required and
|
||||
* embedded in another form.
|
||||
* - `customize_data` (callable): allow to add custom field to the form, which
|
||||
* will be store in the `customs` property
|
||||
*/
|
||||
class AddressType extends AbstractType
|
||||
{
|
||||
@@ -80,9 +82,19 @@ class AddressType extends AbstractType
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['customize_data'] !== NULL && is_callable($options['customize_data'])) {
|
||||
$customsBuilder = $builder->create('customs', NULL, [
|
||||
'compound' => true,
|
||||
'label' => false
|
||||
]);
|
||||
\call_user_func($options['customize_data'], $customsBuilder);
|
||||
$builder->add($customsBuilder);
|
||||
}
|
||||
|
||||
if ($options['null_if_empty'] === TRUE) {
|
||||
$builder->setDataMapper(new AddressDataMapper());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
@@ -98,6 +110,8 @@ class AddressType extends AbstractType
|
||||
->setDefined('null_if_empty')
|
||||
->setDefault('null_if_empty', false)
|
||||
->setAllowedTypes('null_if_empty', 'bool')
|
||||
->setDefined('customize_data')
|
||||
->setAllowedTypes('customize_data', 'callable')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user