I'm trying to generate a form type in particular the "ProductLanguageType".
I want to generate the ProductLanguageType as many times as the current numbers of existing languages in the Language table.
For example if I have (English, French, Russian, Chinese) in the Language table, it would generate 4 ProductLanguageType form on the same page.
I would like to know how do I query language table and generate multiple form of the same type on the same page, is the form builder capable of doing it or is there another workaround? Been having some trouble with this for some time now and would be happy to find a good solution for this.
ProductLanguageType:
class ProductLanguageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add('id_language', 'entity', array(
'class' => 'AdminBundle:Language',
'data_class' => 'MainAdminBundleEntityLanguage',
'property' => 'language'
)
)
->add('name', 'text')
->add('description', 'ckeditor', array(
'config_name' => 'admin',
'config' => array(
'filebrowser_image_browse_url' => array(
'route' => 'elfinder',
'route_parameters' => array('instance' => 'default'),
),
)
))
->add('short_description', 'text');
}
public function getName(){
return 'productLanguage';
}
}
ProductType(ProductLanguageType is embeded in here):
class ProductType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
$builder->add('productLanguage', new ProductLanguageType())
->add('id_seller','text')
->add('price','text')
->add('cost_price','text')
->add('retail_price','text')
->add('hot', 'checkbox')
->add('featured', 'checkbox')
->add('new', 'checkbox')
->add('free_shipping', 'checkbox')
->add('status','text') //active or inactive, to be decided if hidden or visible
->add('Add', 'submit');
}
}
See Question&Answers more detail:
os