Drupal 7 drupal alter节点编辑表单
如何将自定义配置区域添加到“编写信息”和“发布选项”部分下方的节点编辑表单中?您可以使用。 示例如下:Drupal 7 drupal alter节点编辑表单,drupal-7,hook-form-alter,Drupal 7,Hook Form 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
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'),
);
}
}
现在存储数据我鼓励您查看该项目;它有许多代码示例和大量文档。
此外,请查看有关不同类型表单元素的更多信息。
希望这有帮助。以下代码将生成所附图像中的最后一个菜单:
$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,
),
);
注:表格在hook\u form\u alter中非常感谢您的输入,但我的意思与下面的答案类似:您的答案与我提供的答案完全相同。非常相同,但配置区域的位置正是我试图实现的。您的代码毫无疑问地工作了,但我试图实现不同的布局。这只是上面完美工作的代码的一个旁注:您可以通过使用如下保护条件来避免条件嵌套:
if($type!='my_content_type'){return;}
。下面的代码现在不是嵌套的(预期的),这使您的代码更具可读性。