Reputation: 15742
I want to use Symfony's FormFactory for handling FormType and FormHandler.
Unfortunatly I don't know what arguments are required to start the FormFactory service, I looked into the constructor of the Form-Class but there where allot of dependencies I can't really order.
<service id="loc_article.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument></argument>
<argument></argument>
<argument />
</service>
<service id="loc_article.form.type" class="LOC\ArticleBundle\Form\Type\ArticleFormType">
<argument>LOC\ArticleBundle\Entity\Article</argument>
</service>
<service id="loc_article.form.handler" class="LOC\ArticleBundle\Form\Handler\ArticleFormHandler" scope="request" >
<argument type="service" id="loc_article.form" />
<argument type="service" id="request" />
<argument type="service" id="loc_article.manager" />
</service>
So what arguments do I have to pass?
Upvotes: 1
Views: 3812
Reputation: 10072
For all yaml users - A working example for symfony 2.4~
:
services:
chocolate_factory.contact.form:
class: Symfony\Component\Form\Form
factory_method: createNamed
factory_service: form.factory
arguments: [form_name, form_name]
chocolate_factory.contact.form.type:
class: %anchorbrands_common.contact.form.type.class%
arguments: [null]
tags:
- { name: form.type, alias: form_name}
Upvotes: 4
Reputation: 15002
CreateNamed method of FormFactory
class takes FormType
and name of the FormType
respectively.
Edit:
Actually name is not related to FormType
. It can be any arbitrary name.
Added service declaration.
<service id="loc_article.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument>los_article_form</argument>
<argument>los_article_form_name</argument>
<argument />
</service>
<service id="loc_article.form.type" class="LOC\ArticleBundle\Form\Type\ArticleFormType">
<tag name="form.type" alias="los_article_form" />
<argument>LOC\ArticleBundle\Entity\Article</argument>
</service>
Upvotes: 2