@denis
To convert a smallint field to a boolean field in a Symfony form, you can use a data transformer. Below is an example of how you can achieve this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// src/Form/DataTransformer/SmallIntToBooleanTransformer.php namespace AppFormDataTransformer; use SymfonyComponentFormDataTransformerInterface; class SmallIntToBooleanTransformer implements DataTransformerInterface { public function transform($value) { return (bool) $value; } public function reverseTransform($value) { return $value ? 1 : 0; } } |
1 2 3 |
services: AppFormDataTransformerSmallIntToBooleanTransformer: tags: ['form.type'] |
1 2 3 4 5 6 7 8 9 10 11 |
use AppFormDataTransformerSmallIntToBooleanTransformer; // Inside your form type class public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('is_active', CheckboxType::class, [ 'required' => false, ]); $builder->get('is_active')->addModelTransformer(new SmallIntToBooleanTransformer()); } |
This will allow you to convert the smallint value to a boolean value in your form.