0

I have an entity Category that has Category children like a tree. I have a CategorySelectorType that has a few non-mapped fields which determine what Category should be set to the form data.

I want to be able to include that CategorySelectorType in any entity and update the mapped property in the entity on which the CategorySelectorType is being used.

Imagine

ArticleType.php

$builder->add('title') ;
$builder->add('category','category_selectory') ;

So when binding, the category property should be updated with whatever Categpru was chosen using the CategorySelectorType.

I tried doing it in an event lister durint POST_BIND but I get

Warning: ReflectionProperty::getValue() expects parameter 1 to be object, null given in /home/neron/sites/zabulu/trunk/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 697

And it seems to be caused by

 UniqueEntityValidator ->validate (object(Category), object(UniqueEntity)) 
Perry
  • 11,172
  • 2
  • 27
  • 37
d0001
  • 2,162
  • 3
  • 20
  • 46

1 Answers1

1

I think I understand the question and if I do, the correct way to do this would be something like:

$builder->add('category', new CategorySelectorType(), array('empty_value' => 'Choose a category'));
Adam Elsodaney
  • 7,722
  • 6
  • 39
  • 65