【问题标题】:Drupal & custom module using page_build hook to add content to the sidebarDrupal 和自定义模块使用 page_build 钩子将内容添加到侧边栏
【发布时间】:2014-01-28 19:14:33
【问题描述】:

我正在尝试构建一个必须将表单添加到 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 自定义模块的新手

【问题讨论】:

  • 这个表格的目的是什么?是节点创建还是搜索表单?
  • 我需要在侧边栏添加一个类似表单的过滤器,根据它的内容发生变化

标签: php drupal drupal-7 drupal-modules


【解决方案1】:
  • 创建块
/** * 实现 hook_block_info()。 */ 功能 custom_block_block_info() { $blocks = 数组(); $blocks['my_block'] = 数组( 'info' => t('我的自定义块'), ); 返回$块; }
  • 向自定义块添加表单 hook_block_view
  • 将块添加到 sidebar_first

【讨论】:

    猜你喜欢
    • 2017-11-15
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 2011-06-16
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多