drupal改变节点编辑形式

sis*_*sko 5 drupal-7 hook-form-alter

如何在" 创作信息发布选项"部分下方的节点编辑表单中添加自定义配置区域?

awm*_*awm 13

您可以使用 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'),
   );
  } 
}
Run Code Online (Sandbox Code Playgroud)

现在,为了存储数据,我鼓励您查看示例项目; 它有许多代码示例,包含大量文档.另外,请检查表单API以获取有关不同类型表单元素的更多信息.希望这可以帮助.


sis*_*sko 4

以下代码生成附图中的最后一个菜单:

    $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,
        ),
    );
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ps:表单在hook_form_alter中