【发布时间】:2023-03-10 17:01:01
【问题描述】:
如何在创作信息和发布选项部分下方的节点编辑表单中添加自定义配置区域?
【问题讨论】:
如何在创作信息和发布选项部分下方的节点编辑表单中添加自定义配置区域?
【问题讨论】:
您可以使用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,了解有关不同类型表单元素的更多信息。 希望这会有所帮助。
【讨论】:
if ($type != 'my_content_type') { return; }。以下代码现在不是嵌套的(有意),这使您的代码更具可读性。
以下代码生成附图中的最后一个菜单:
$form['barclays_epdq'] = array(
'#type' => 'fieldset',
'#access' => TRUE,
'#title' => 'Barclays ePDQ',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#weight' => 100,
'barclays_epdq_active' => array(
'#type' => 'checkbox',
'#title' => 'Enable this webform to send users to your Barclays ePDQ store to make a payment',
'#default_value' => $active_state,
),
);
ps:表单在 hook_form_alter 中
【讨论】: