Symfony2 - Add Entity field type to form with event subscriber class
===

I am doing something very similar to this cookbook example http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html#adding-an-event-subscriber-to-a-form-class

The main difference is that my field type is an entity and not a text type.

So my field subscriber preSetData method looks like this:

    public function preSetData(DataEvent $event)
    {
        $data = $event->getData();
        $form = $event->getForm();
    
        if (null === $data) {
            return;
        }
    
        if(!$data->getIsCategorized()){
    
        	$form->add(
    
        		$this->factory->createNamed('categories', 'entity', array(
                'class' => 'My\PostBundle\Entity\Category',
                'property'     => 'name',
                'multiple'     => true,
                'label' => 'Category'
                )
                )
    		);
        }
    }

This is giving the following error

    Class does not exist
    500 Internal Server Error - ReflectionException 

Is it possible to attach an entity field type to a form using a field event subscriber in this fashion?

