drupal alter node edit form

后端 未结 2 1395
深忆病人
深忆病人 2021-02-02 04:16

How can I add a custom configuration area to a node edit form just beneath the Authoring Information & Publishing Options section?

2条回答
  •  鱼传尺愫
    2021-02-02 04:56

    You can use hook_form_FORM_ID_alter(). Example below:

    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'),
       );
      } 
    }
    

    Now For storing the data I encourage you to see the examples project; it has many code examples with lots of documentation. Also, Check the Form API for more information on different types of form elements. Hope this helps.

提交回复
热议问题