Drupal:如何在 hook_field_widget_form 中使用字段集
所以我有我的 hook_field_schema 定义列,并且 hook_field_widget_form 已设置并正确保存所有列值。
但是,一旦我将两个字段放入字段集中,这些值就永远不会保存或更新。我尝试过设置#tree =>到处都是 FALSE,这也不起作用。
我缺少什么?只是不支持吗?我应该使用 form_alter 钩子或其他东西将它们移动到字段集中吗?
So I have my hook_field_schema defining columns, and hook_field_widget_form is set up and saving all of the column values correctly.
But as soon as I put two of the fields inside of a fieldset, those values never save or get updated. I've tried setting #tree => FALSE all over the place and that isn't working either.
What am I missing? Is it just unsupported? Should I be using a form_alter hook or something to move them into a fieldset?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有同样的问题,找不到解决方案。在尝试了很多事情之后,结果证明这是一件简单到不合逻辑的事情。嗯,在 Drupal 新手的眼中。
起初,我有这样的东西(精简版本):
并将字段添加到字段集中:
在尝试了很多不同的场景之后,我发现接下来的代码行确实(有点)有效。我没有插入字段集,而是将元素转换为如下所示的字段集:
然后我向元素添加了字段:
注意:#title 和 #weight 等一些变量由“主页 » 管理 » 结构 » 内容类型 » [您的内容”控制TYPE]”,其他的(如#collapsible和#collapsed)可以在这里定义。
希望这对您有帮助!
I had the same problem and couldn't find a solution. After trying many things, it turned out to be something as simple as illogical. Well, in the eyes of a Drupal newbie.
At first I had something like this (stripped down version):
and added fields to the fieldset:
After trying lots of different scenarios I found out the next lines of code did (sort of) work. Instead of inserting a fieldset, I turned the element into a fieldset like this:
Then I added fields to the element:
NB: some variables like #title and #weight are controlled by "Home » Administration » Structure » Content types » [YOUR CONTENT TYPE]", others (like #collapsible and #collapsed) can be defined here.
Hope this helps you out!
我知道这是一个老问题,但是这个问题有一个解决方案,解释在本文中,
#process
部分用于正确保存字段。编辑:正如@alexkb的评论所解释的那样,文章的作者更新了他的自定义字段示例 并删除了#process hack。如需更好的解决方案,请使用 GitHub 代码。
I know it is an old question, but there is a solution for this problem, explained in this artice, the
#process
part is what is used to save the fields properly.EDIT: As the comment of @alexkb explains, the author of the article has updated his custom field sample and has removed the #process hack. For a better solution, use the GitHub code.
查看物理模块。基本上是:
您可以使用以下方式定义子字段:
Look at the physical module. Basically do:
You can define the sub fields with: