在模塊的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