如何在创作信息和发布选项部分下面的节点编辑表单中添加自定义配置区域?
最佳答案
您可以使用hook_form_FORM_ID_alter()。
下面的例子:
function my_module_form_node_form_alter(&$form, $form_state) {
// if you are targeting a specific content type then
// you can access the type:
$type = $form['#node']->type;
// Then
if ($type == 'my_content_type') {
// use a contact settings for the sake of this example
$form['contact'] = array(
'#type' => 'fieldset',
'#title' => t('Contact settings'),
'#weight' => 100,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// add simple checkbox to the field set
$form['contact']['approve'] = array(
'#type' =>'checkbox',
'#title' => t('Contact me'),
);
}
}
现在,为了存储数据,我鼓励您查看examples项目。它有许多带有大量文档的代码示例。
另外,请检查the Form API以获取有关不同类型的表单元素的更多信息。
希望这可以帮助。
关于drupal-7 - drupal alter node编辑表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13529636/