以编程方式创建 Drupal 7 内容类型时,有没有办法添加字段元组?
在 Drupal 7 中,我想创建一个 Person 内容类型。一个人可能有多个配置文件 - 管理员应该能够选择哪个配置文件将被视为主要配置文件。所以,这意味着我需要一个由以下组成的元组:
一个文本区域,用于配置文件文本
一个复选框,表明这是主要配置文件
一个文本框,为了命名这个特定的配置文件,
我需要像任何列表一样的功能:我可以单击“添加另一个项目”,然后将出现一组所有三个字段。
我对如何执行此操作有一个模糊的想法,但它涉及使用表单 API 在每次呈现表单之前添加字段,以及必要的 AJAX 行为。这似乎有点过于复杂,因为这还需要创建一个额外的数据库表来保存这些附加字段。
有没有一种相对简单的方法可以仅通过 hook_install()
来完成此操作?
In Drupal 7, I'd like to create a Person content type. A person may have multiple profiles - an administrator should be able to select which profile will be considered the primary one. So, that means that I need a tuple consisting of:
A textarea, for the profile text
A checkbox, indicating that this is the primary profile
A textbox, for naming this particular profile
I need functionality to behave like that of any of the lists: I can click "Add another Item", and a set of all three of these fields will appear.
I have a vague idea of how this can be executed, but it involves using the form API to add fields before the form renders each time, as well as the necessary AJAX behavior. This seems a bit overcomplicated, since this would also necessitate creating an additional DB table to hold these tacked-on fields.
Is there a relatively simple way of doing this solely through hook_install()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 drupal.org/project/profile2,也可以使用标准 Drupal 功能来完成它,即创建一个名为“myprofile”的内容类型,并添加所有需要的字段。然后将一个 nodereferece (http://drupal.org/project/references) 字段添加到用户标准配置文件中,该配置文件将指向您的“myprofile”内容类型。
因此,该用户创建的所有“我的个人资料”内容都将是他的个人资料,而他的标准个人资料中指向的内容将是他的默认内容。
我希望它足够清楚)
You can use drupal.org/project/profile2 or you can complete it using standard Drupal functionality, i.e. create a content type named, let's say, 'myprofile' and add all the fields use need. Then add a nodereferece (http://drupal.org/project/references) field to the user standard profie that would point to your 'myprofile' content type.
So all the 'myprofile' content, created by that user would be his profiles and the one pointed in his standard profile will be his default.
I hope it's clear enough )