我有一个可翻译的实体,使用doctrine2的可翻译行为.
我正在尝试构建一个如下所示的表单:
| French |English| Spanish | +--+--------| |---------+------------+ | | | name: [___my_english_name___] | | | | title: [___my_english_title__] | | | +------------------------------------------+ Order: [___1___] Online: (x) Yes ( ) No
所以基本上都有订单&不可翻译的对象的在线属性,以及名称& title属性具有可翻译的行为.
如果我的图纸不清楚:表单包含一个1个选项卡,每个区域设置保存可翻译的字段.
我所遇到的问题是,默认情况下,Symfony2将表单绑定到一个实体,但是这个原则可翻译的行为会迫使我每个语言环境有一个实体.个人而言,学说行为是正确的(我喜欢它),但是我无法创建一个允许我在所有语言环境中编辑实体的表单 – 以相同的形式.
到目前为止,我的主要形式是:
namespace myApp\ProductBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; /** * Form for the productGroup. */ class ProductType extends AbstractType { /** * Decide what field will be present in the form. * * @param FormBuilder $builder FormBuilder instance. * @param array $options Custom options. * * @return null; */ public function buildForm(FormBuilder $builder,array $options) { //Todo: get the available locale from the service. $arrAvailableLocale = array('en_US','en_CA','fr_CA','es_ES'); //Render a tab for each locale foreach ($arrAvailableLocale as $locale) { $builder->add( 'localeTab_' . $locale,new ProductLocaleType(),array('property_path' => false,//Do not map the type to an attribute. )); } //Uni-locale attributes of the entity. $builder ->add('isOnline') ->add('sortOrder'); } /** * Define the defaults options for the form building process. * * @param array $options Custom options. * * @return array Options with the defaults values applied. */ public function getDefaultOptions(array $options) { return array( 'data_class' => 'myApp\ProductBundle\Entity\Product',); } /** * Define the unique name of the form. * * @return string */ public function getName() { return 'myapp_productbundle_producttype'; } }
和表单:
<?PHP namespace MyApp\ProductBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use invalidArgumentException; /** * Form for the productGroupLocale tabs. */ class ProductLocaleType extends AbstractType { /** * Decide what field will be present in the form. * * @param FormBuilder $builder FormBuilder instance. * @param array $options Custom options. * * @return null; */ public function buildForm(FormBuilder $builder,array $options) { $builder->add('name','text',array('data' => ???)); $builder->add('title',array('data' => ???)); } /** * Define the defaults options for the form building process. * * @param array $options Custom options. * * @return array Options with the defaults values applied. */ public function getDefaultOptions(array $options) { return array( //'data_class' => 'MyApp\ProductBundle\Entity\Product','name' => '','title' => '',); } /** * Define the unique name of the form. * * @return string */ public function getName() { return 'myapp_productbundle_productlocaletype'; } }