简体   繁体   English

oroCommerce / Symfony 2.8-如何将自定义字段添加到注册表单

[英]oroCommerce/Symfony 2.8 - how to add a custom field to a registration form

Does anyone know a way to add an extra field (VAT ID provided by the Infinitepay Bundle) to oroCommerce's registration form? 有谁知道一种在oroCommerce的注册表格中添加额外字段(由Infinitepay Bundle提供的增值税ID)的方法? I can't find a way to do it. 我找不到办法。

The issue is that this field isn't part of the CustomerUser entity, but of the associated Customer entity. 问题在于该字段不是CustomerUser实体的一部分,而是关联的Customer实体的一部分。 So the normal builder->add() command doesn't work. 因此普通的builder-> add()命令不起作用。 I'm also having trouble finding a way to put any code into a Bundle of my own and get it to work (instead of hacking the core). 我也很难找到一种方法来将任何代码放入我自己的捆绑软件中并使之工作(而不是破解内核)。 I've already read the Symfony docs, but they didn't help much. 我已经阅读过Symfony文档,但是它们并没有太大帮助。

First, you need to create symfony form extension, see documentation 首先,您需要创建symfony表单扩展,请参阅文档

Then add the VAT ID field to form builder and add a POST_SUBMIT listener with a lower priority than this one 然后将VAT ID字段添加到表单构建器,并添加一个优先级低于此值的POST_SUBMIT侦听器

In the listener's code, you can map the VAT ID value to the Customer entity. 在侦听器的代码中,您可以将VAT ID值映射到Customer实体。

UPD: UPD:

  1. How exactly am I supposed to use form type extensions? 我应该如何使用表单类型扩展名?

Ok. 好。 Use this gist 使用这个要点

The documentation says they are good for extending field types, not forms. 该文档说,它们适用于扩展字段类型,而不是表单。

It's the same. 一样的。 Any form type can be used as a child (field) of another form type. 任何表单类型都可以用作其他表单类型的子级(字段)。

I can't do it with $builder->add() - that gives me a 500 error because the entity doesn't have that field. 我无法使用$ builder-> add()来执行此操作-由于实体没有该字段,因此出现500错误。

You should add an option 'mapped => false' for your field. 您应该为您的字段添加一个选项'mapped => false'。 See documentation 参阅文件

I also need a way to put it in a bundle of my own, not into the core. 我还需要一种方法将其放在我自己的捆绑包中,而不是放入核心中。

You can modify any form type from your own bundle using form type extensions. 您可以使用表单类型扩展名从自己的捆绑软件中修改任何表单类型。 This is what they were created for. 这就是他们创建的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM