在 Drupal 中动态创建内容类型
我们网站的要求之一是拥有一种内容类型,让您可以动态决定内容类型的总量。
例如,如果我指定数字 10,那么它应该连续生成内容类型,其中一个“textarea”类型和另一个“radio”类型创建 10 次。
本质上以编程方式破坏它,它将创建:
<?php
for(i=0;i<10;i++)
{
echo "<input type = 'textarea'></input>";
echo "<select><option>1</option><option>2</option></select>";
}
?>
如果我涉足简单的 PHP 文件,这非常简单,但对于 Drupal 7 的内容类型 (CCK),它提出的挑战比应有的挑战更大。我尝试过探索允许您动态创建内容类型的模块,并考虑以编程方式创建自定义内容类型,这似乎完全是另一个挑战。
我很好奇是否有人有替代方案并且之前曾尝试过这一挑战。非常感谢您的回答。
谢谢大家
One of our website requirements is to have a content type that let's you decide on the total amount of content types on the fly.
For instance, if I specify a number 10, then it ought to generate the content types consecutively, one of type 'textarea' and another of type 'radio' are created 10 times.
essentially to break it programmatically, it will create:
<?php
for(i=0;i<10;i++)
{
echo "<input type = 'textarea'></input>";
echo "<select><option>1</option><option>2</option></select>";
}
?>
This is pretty straightforward if I was dabbling with simple PHP files, but with Drupal 7's content types (CCK), it is posing a bigger challenge than what it ought to be IMHO. I have tried exploring modules that let you create content types on the fly and considered creating a custom content type programmatically which seems like another challenge altogether.
I am curious if anybody has an alternative for this and has dabbled with this challenge before. Your answers are most appreciated.
Thanks guys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 drupal 7 中创建内容动态类型,您需要遵循以下过程:
更新 *
1) 使用 hook_menu() 创建菜单路径,该菜单路径使用 drupal_get_form()。这将允许您收集用户输入的所有数据,以创建动态内容。
示例:
2) 然后使用:
3) 创建一个数组,用于保存有关内容类型的元数据。
4) 使用node_type_save() 保存/声明您的内容类型。
5) 创建字段,然后附加到您的内容类型。
To create content dynamic types in drupal 7 you will need to follow the below process:
Updated *
1) Create a menu path using hook_menu() which uses drupal_get_form(). This will allow you to gather all data for your users input for the dynamic content creation.
Example:
2) Then use:
3) Create an array which will hold the meta data about your content type.
4) use node_type_save() to save/declare your content type.
5) Create fields and then attach to your content type.