als*_*tor 8 content-type drupal module drupal-7
我正在Drupal 7中构建一个模块(my_module).它具有一些功能,还将创建新的内容类型.在my_module.install中我实现了hook_install(my_module_install)我可以使用更多的hook_install实现在这个模块中创建新的内容类型(my_cck_install)吗?如果(是的),我应该怎么做?另外:我是否在另一个模块中执行此操作?:-)
您不能hook_install在同一模块中使用多个实现; 在PHP中你不能有2个具有相同名称的函数来规则.
您只需要在相同的位置添加新的内容类型hook_install(在/profiles/standard/standard.install中查看标准安装配置文件的工作方式).这就是我总是从安装文件中添加新内容类型的方式(使用推荐模块的示例):
function testimonial_install() {
// Make sure a testimonial content type doesn't already exist
if (!in_array('testimonial', node_type_get_names())) {
$type = array(
'type' => 'testimonial',
'name' => st('Testimonial'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'title_label' => 'Customer / Client Name'
);
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15278 次 |
| 最近记录: |