在 Drupal 中使用单个自定义表单创建多个 CCK 节点

发布于 2024-07-30 07:18:42 字数 938 浏览 6 评论 0原文

我需要一个允许同时创建多个相关节点的表单。 所有节点都涉及 CCK 字段。

我想尽可能多地使用 CCK 的内置验证、提交、输入小部件和安全功能。

在 Drupal 6 中实现这一目标的最佳方法是什么? 是否有“最佳实践”或文档?

我可以看到以下三种可能性。 我希望得到有关这些方法是否有效或者是否有更好的选择的反馈。

1.

  • 从内容类型 foo 的标准节点创建表单开始。
  • 通过添加内容类型栏的字段来修改表单,使用钩子 form_alter [可以直接插入内容类型栏的 cck 小部件吗?]
  • 在提交表单时使用自定义提交处理程序创建类型栏的节点 [可以调用标准cck处理程序吗? 或者我是否需要“手动”构造节点对象,进行自己的验证并使用node_save?]

2.

  • 创建一个新的自定义表单,该表单连接相关内容类型的“正常”节点创建表单。
  • 然后使用钩子 form_alter 根据需要修改表单。
  • 允许标准 cck 提交处理程序来完成创建节点的工作。

3.

  • 从头开始创建自定义表单
  • 使用节点准备、节点保存等在我自己的提交处理程序中创建节点。

如果找到关于重用标准节点创建表单的文档,但没有提到同时创建多个节点。

Advomatic 网站上的一篇文章中记录了如何使用钩子 nodeapi 和钩子 form_alter,但特定的方法 descrube 似乎需要使用“虚拟”字段污染其中一种内容类型。

非常感谢您的帮助!

I need a form which will allow creation of several related nodes at the same time. All of the nodes involve CCK fields.

I would like to use as much of CCK's built-in validation, submission, input widget, and security functionality as possible/practical.

What is the best way to accomplish this in Drupal 6? Are there 'best practices' or docs anywhere?

Here are 3 possibilities I can see. I would love feedback on whether any of these would work, or if there are even better options.

1.

  • start with the standard node creation form for content type foo.
  • modify the form by adding fields for content type bar, using hook form_alter [can cck widgets for content type bar be inserted directly?]
  • use a custom submit handler to create node of type bar when the form is submitted
    [can the standard cck handler be called? or do i need to 'manually' construct the node object, do my own validation, and use node_save?]

2.

  • create a new, custom form that concatenates the 'normal' node creation forms for the relevant content types.
  • then use hook form_alter to modify the forms as necessary.
  • allow standard cck submit handlers to do the work of creating the nodes.

3.

  • create a custom form from scratch
  • create the nodes in my own submit handlers, using node prepare, node save, etc.

If found documentation on re-using the standard node creation form, but creating multiple nodes at the same time is not mentioned.

Using hook nodeapi and hook form_alter is documented in a post on advomatic's site, but the particular method descrube seems to require polluting one of the content types with 'dummy' fields.

Thank you very much for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爺獨霸怡葒院 2024-08-06 07:18:43

如果第二种类型的只需要用户提供一两个额外的输入(字段),我会采用您的方法一。

但鉴于您的澄清,似乎 foobar 足够不同且复杂,因此您的方法二似乎更合理。

将两个表单连接成一个表单,并隐藏要从 foo 字段(或节点,在创建后)填充的 bar 字段。 在表单验证和提交函数中,您必须再次分离表单,以便可以分别调用两者的标准验证/提交处理程序。

我还没有这样做,所以我不确定这与 cck 功能的配合效果如何,但我希望它能够很好地工作,尝试一下。

If the 2nd type bar needs only one or two additional inputs (fields) from the user, I would go with your approach one.

But given your clarification it seems that foo and bar are sufficiently different and complex, so your approach two seems more reasonable.

Concatenate both forms into one and hide the bar fields that you want to populate from the foo fields (or node, after you created it). In the forms validate and submit functions, you'll have to separate the forms again so that you can call the standard validation/submit handlers for both separately.

I have not done this yet, so I'm not sure how well this will play with the cck functionality, but I would expect it to work reasonably well to give it a try.

找个人就嫁了吧 2024-08-06 07:18:43

为什么不只使用 hook_nodeapi 来处理某些内容类型的节点创建。

只需设置一个测试条件来查看 $node->type = 'foo' 是否存在,然后使用预定义字段中的值运行一个函数来创建两个或任意多个节点。 您甚至可以将 hook_nodeapi 设置为仅在 $op 几乎准备好将节点插入数据库时​​运行,从而确保对象在传递到需要创建的新节点之前已通过适当的验证运行。

http://api.drupal.org/api/function/hook_nodeapi/6 此页面列出了 $op 变量的所有可用操作及其用途。

我希望这有帮助

why not just use hook_nodeapi to handle the node creation for certain content types.

just set up a test condition to see if $node->type = 'foo', and then run a function to create two nodes or however many, using the values from the predefined fields. you can even set hook_nodeapi to only run when the $op is almost ready to insert the node into the database, thus ensuring the object has been run through appropriate validation before being passed on to the new nodes that need to be created.

http://api.drupal.org/api/function/hook_nodeapi/6 this page has a list of all available operations for the $op variable and what they do.

I hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文