I have form with field type entity
on this field I have query_builder
which return query and 'property' => 'name',
. And my question what need to do in data transformer for change select name, need complicated with several filed, example - name_address_office. Using Symfony 2.8 I need dataTransformer approach
my form
class OutBoundInvoiceRowType extends AbstractType
{
/**
* @var array
*/
private $vatClasses;
/**
* @var Container
*/
private $container;
/**
* @var EntityManager
*/
private $em;
/**
* OutBoundInvoiceRowType constructor.
* @param Container $container
* @param $vatClasses
*/
public function __construct(
Container $container,
$vatClasses
) {
$this->container = $container;
$this->vatClasses = $vatClasses;
$this->em = $this->container->get('doctrine.orm.entity_manager');
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('location', 'entity', array(
'class' => Location::class,
'property' => 'name',
'empty_value' => 'Choice Location',
'query_builder' => self::getLocations(),
'required' => false
))
->add('vat', ChoiceType::class, [
'choices' => ?,
'required' => true,
])
$builder->get('vat')
->addModelTransformer(new VatTransformer($this->container));
}
and my VatTransformer:
class VatTransformer implements DataTransformerInterface
{
/**
* @var Container
*/
private $container;
/**
* @var EntityManager
*/
private $em;
/**
* LocationTransformer constructor.
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
$this->em = $this->container->get('doctrine.orm.entity_manager');
}
/**
*
* @param Location|null $issue
* @return string
*/
public function transform($issue)
{
if (null === $issue) {
return '';
}
}
}
in function transform $issue
have null
and when return ''
nothing change in form, still have 'property' => 'name',
on choice, What need to do in data transform name ?
this now I have
and this what I need
need name of several parts
UPDATE
Ok. I have choice field vat
and I need build data in choice for vat field like - from some entity field, example entity Location (id, name)
How this realized with dataTransformer ?