【发布时间】:2012-12-23 04:18:06
【问题描述】:
我发现,使用新字段和正文字段创建内容类型的问题似乎已记录并显示在多个位置。如何使用我在另一个模块中创建的现有字段类型以编程方式将字段类型包含到新内容类型中?
【问题讨论】:
标签: drupal content-type
我发现,使用新字段和正文字段创建内容类型的问题似乎已记录并显示在多个位置。如何使用我在另一个模块中创建的现有字段类型以编程方式将字段类型包含到新内容类型中?
【问题讨论】:
标签: drupal content-type
将创建新内容类型的代码我们应该添加到.install 文件中。
让我们添加hook_install():
<?php
function your_module_name_install() {
// use get_t() to get the name of our localization function for translation
// during install, when t() is not available.
$t = get_t();
// Define the node type.
$node_example = array(
'type' => 'node_example',
'name' => $t('Example Node'),
'base' => 'node_content',
'description' => $t('This is an example node type with a few fields.'),
'body_label' => $t('Example Description')
);
// Complete the node type definition by setting any defaults not explicitly
// declared above.
// http://api.drupal.org/api/function/node_type_set_defaults/7
$content_type = node_type_set_defaults($node_example);
node_add_body_field($content_type);
// Save the content type
node_type_save($content_type);
}
【讨论】: