簡體   English   中英

使用page_build掛鈎將內容添加到側邊欄的Drupal和自定義模塊

[英]Drupal & custom module using page_build hook to add content to the sidebar

我正在嘗試構建一個自定義模塊,該模塊必須向sidebar_first添加表單。 我嘗試使用page_build掛鈎,但是沒有用。

function module1_page_build(&$page){
     drupal_set_message("Inside page builder");
     $page['sidebar_first']['filters'] = array(
        '#markup' => drupal_form_build('filter_formbuild',$formstate=NULL),
        '#prefix' => '<div class="filters">',
        '#suffix' => '</div>',
    );    
}

我創建了一個函數filter_formbuild,它返回一個像這樣的表單數組。 函數filter_formbuild(){

$form = array();    



$form['title'] = array(
    '#title' => 'Title',
    '#type' => 'textfield',
    '#size' => '100',
);

$form['url'] = array(
    '#title' => 'Name',
    '#type' => 'textfield',
    '#size' => '100',
);

$form['notes'] = array(
    '#title' => 'Notes',
    '#type' => 'textarea',
            '#maxlength' => 200, 
    '#size' => '30',
);

    $form['author'] = array(
    '#title' => 'Author(s)',
    '#type' => 'textfield',
            '#maxlength' => 30, 
    '#size' => '100',   
);

    $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',       
);



     return $form;
}

我認為該鈎子沒有啟動,因為set_message也無法正常工作。 有人可以建議另一種方法來執行此操作,還是我的實現中有任何錯誤。 我是drupal自定義模塊的新手

  • 創建一個塊
/**
 * Implements hook_block_info().
 */
function custom_block_block_info() {
  $blocks = array();
  $blocks['my_block'] = array(
    'info' => t('My Custom Block'),
  );

  return $blocks;
}
  • 將表單添加到自定義塊hook_block_view
  • 將您的塊添加到sidebar_first

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM