在模块的hook_node_info()中,添加'module'
属性(请参阅http://api.drupal.org/api/function/hook_node_info/6)。
例如:
/**
* Implementation of hook_node_info().
*/
function foo_node_info() {
return array(
'footypea' => array(
'name' => t('Foo Type A'),
'description' => t('This is Foo Type A'),
'module' => 'footypea', //This will be used for hook_form()
),
'footypeb' => array(
'name' => t('Foo Type B'),
'description' => t('This is Foo Type B'),
'module' => 'footypeb', //This will be used for hook_form()
),
);
}
现在,您可以添加以下hook_form()为每种类型的实现(见http://api.drupal.org/api/function/hook_form/6)。
/**
* Implementation of hook_form().
*/
function footypea_form(&$node, $form_state) {
// Define the form for Foo Type A
}
/**
* Implementation of hook_form().
*/
function footypeb_form(&$node, $form_state) {
// Define the form for Foo Type B
}
这里的技巧是每个元素的hook_node_info()
模块属性不必是相同的实施hook_node_info()
模块。定义的每个类型都可以具有唯一的模块属性,用于实现类型特定的钩子。
+1:是的,这是绝对正确的,对于其他内容类型特定的钩子也是如此:例如, 'footypea_access($ op,$ node,$ account)','footypeb_access($ op,$ node,$ account)','footypea_validate($ node,&$ form)','footypeb_validate($ node,&$ form) ($ node)','footypea_insert($ node)','footypea_update($ node)','footypeb_update($ node)','footypea_delete($ node)','footypeb_delete($ node)',等等 – Sk8erPeter 2012-01-04 15:51:22