doulu8341 2014-01-28 19:14
浏览 39
已采纳

使用page_build挂钩的Drupal和自定义模块将内容添加到侧边栏

I'm trying to build a custom module that has to add a form to the sidebar_first. I tried using page_build hook but that did not work.

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

I created a function filter_formbuild which returns a form array which is something like this. function 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;
}

I think the hook was not initiated since the set_message was also not working. Can someone suggest another way to do this or is there any errors in my implementation. I'm new to drupal custom modules

  • 写回答

1条回答 默认 最新

  • duanhegn231318 2014-01-29 05:39
    关注
    • Create a block
    /**
     * Implements hook_block_info().
     */
    function custom_block_block_info() {
      $blocks = array();
      $blocks['my_block'] = array(
        'info' => t('My Custom Block'),
      );
    
      return $blocks;
    }
    
    • Add a form to your custom block hook_block_view
    • Add your block to the sidebar_first
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误