【发布时间】:2010-06-06 16:39:34
【问题描述】:
是否可以在一个模块中声明和管理多个自定义内容类型?我正在创建一个需要四种自定义内容类型的网站,我想从一个模块管理它们,而不是为每种内容类型创建模块。经过一番测试,我发现这似乎是不可能的。因为,除非 hook_form 和 content type 共享相同的模块名称,drupal 不会调用 hook_form。
这就是我想做的-
function mycontent_node_info(){
return array(
'mycontent1' => array(
'name' => t('....'),
'module' => 'mycontent',
'description' => t('...),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('content body'),
),
'mycontent2' => array(
.......
),
'mycontent3' => array(
......
),
'mycontent4' => array(
......
),
);
}
function mycontent1_form(&$node){
$form['control1'] = array(
'#type' => 'select',
'#options' => array(
'0' => t('selection 1'),
'1' => t('selection 2'),
),
'#attributes' => array('id'=>'control1'),
);
$form['control2'] = array(
'#type' => 'select',
'#options' => array(
'0' => t('1'),
'1' => t('2'),
'2' => t('3'),
'3' => t('4'),
),
'#attributes' => array('id'=>'control2'),
);
return $form;
}
function mycontent2_form(&$node){
....
}
function mycontent3_form(&$node){
....
}
function mycontent4_form(&$node){
....
}
我在这里做错了什么还是不可能,除了为每种内容类型创建模块之外别无选择。非常感谢您的帮助。
【问题讨论】: