将模块输出添加到块
问题描述:
我有一个模块负责处理ubercart(产品套件)中的特殊产品。该模块负责根据用户的选择即时制作产品套件。我在我的uc_bundle_manager.module文件中使用了下面的函数。我似乎无法弄清楚如何渲染我的主题(作为一个块)的输出。我不确定如何访问或创建$ vars变量,以便它可以在我的模板中使用。目前该函数只是返回正确的产品工具包的节点想法(这在我的调试输出中工作得很好)。任何帮助是极大的赞赏。谢谢!将模块输出添加到块
function clothing_filter_form_submit($form, &$form_state)
{
/*--Form Values--*/
$vals = array($form_state['values']['shirt'],$form_state['values']['hoodie'],$form_state['values']['hats']);
/*--DB isn't setup for this relationship. Maybe a better SQL query is better but TODO--*/
$sql = "SELECT nid, product_id FROM uc_product_kits";
$result = db_query($sql);
while($row = mysql_fetch_assoc($result))
{
$rid = $row['nid'];
$bundles[$rid][] = $row['product_id'];
}
foreach($bundles as $key => $bundle)
{
$count = 0;
foreach($vals as $val)
{
if(in_array($val,$bundle))
{
$count++;
}
}
//--If we match 3 items--//
if($count == 3)
{
$selected_bundle = $key;
}
}
return $selected_bundle;
}
答
您将需要使用hook_block_info()函数来生成一个块。我假设你正在使用d7。
下面是一个示例代码
/**
* Implements hook_block_info().
*/
function trails_block_info() {
$blocks['history'] = array(
'info' => t('History'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
干杯, 维沙尔
+0
对不起,我正在使用D6。 –
您需要澄清一点 - 上面的函数是一个表单提交功能。那些不产生输出,并且不返回值!他们只返回URL重定向成功提交后(或者什么也不做,在这种情况下,用户停留在他提交表单的页面上)。那么你想在哪里显示你提到的'block'(以及与表单提交功能的关系)? –