I use symfony-form component as standalone.
Here is composer.json :
"symfony/form": "2.7.*",
"symfony/validator": "2.7.*",
"symfony/config": "2.7.*",
"symfony/templating": "2.8.*@dev",
"symfony/twig-bridge": "3.0.*@dev",
"symfony/framework-bundle": "2.7.0-BETA1",
"symfony/doctrine-bridge":"2.7.1"
I want to create choice form element with entity type. But how ? When i set string parameter, it says "Could not load type "entity".
$builder
->add('groups', 'entity', array(
'class' => 'Application\Groups\Entity\Group',
'choices' => $this->group->getUsers()
));
How to load entityType in form? Here is my form initialization:
/**
* @return Component\Form\FormFactoryInterface
*/
public function getFormFactory()
{
if(!$this->formFactory){
$this->formFactory = Component\Form\Forms::createFormFactoryBuilder()
->addExtension(new Extension\HttpFoundation\HttpFoundationExtension())
->addExtension(new Extension\Templating\TemplatingExtension($this->engine->getEngine(), null, array(
$VENDOR_FRAMEWORK_BUNDLE_DIR . '/Resources/views/Form',
PATH_APPLICATION.'/layouts/form_widgets'
)))
//->addExtension(new CsrfExtension($this->initCSRF()))
->addExtension(new Extension\Validator\ValidatorExtension($this->initValidator()))
->getFormFactory();
}
return $this->formFactory;
}
Maybe i should to set object new Symfony\Bridge\Doctrine\Form\Type\EntityType(). But it needs ManagerRegistry which i have not. I really don't need ManagerRegistry because i have only one EntityManager which manage all my entities by own. Perhabs i should to make some fake object-wrapper which implements ManagerRegistry interface and inject it to new EntityType()
Please help me with this huge trouble.
A little late, but here is a very ugly way to get you started:
The fake ManagerRegistry initialisation:
This goes to formFactory:
And the fake ManagerRegistry:
These codes are not for production, just for ideas, they are mostly from: vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/ManagerRegistryTest.php
I will update this answer, if I come up with a good way of doing this.