在Drupal中实现自定义模块


Implementing Custom Modules in Drupal

我是Drupal的新手,我必须为ubercart编写一种新的自定义支付方法。我简要地了解了Drupal的钩子系统。

在ubercart-api文档中,http://www.ubercart.org/docs/api/hook_payment_method:

<?php
function uc_payment_payment_method() {
  $methods[] = array(
    'id' => 'check',
    'name' => t('Check'),
    'title' => t('Check or Money Order'),
    'desc' => t('Pay by mailing a check or money order.'),
    'callback' => 'uc_payment_method_check',
    'weight' => 1,
    'checkout' => TRUE,
  );
  return $methods;
}
?>

然而,当我看到贝宝模块是如何实现的:

$methods[] = array(
    'id' => 'paypal_wps',
    'name' => t('PayPal Website Payments Standard'),
    'title' => $title1 . $title2,
    'review' => t('PayPal'),
    'desc' => t('Redirect users to submit payments through PayPal.'),
    'callback' => 'uc_payment_method_paypal_wps',
    'redirect' => 'uc_paypal_wps_form',
    'weight' => 1,
    'checkout' => FALSE,
    'no_gateway' => TRUE,
  );

有一些特殊的字段,如重定向和no_gateway。我在哪里可以找到这些字段的文档,看看这些字段实际做了什么?

非常感谢你的帮助。

您也可以在http://api.ubercart.me/.

但我看到,对于hook_uc_payment_method(),这里没有比您提到的文档更多的信息。

以PayPal支付模块为例,我发现重定向回调指定了重定向到异地支付网关的最终结账按钮后面的代码。

因此,uc_paypal_wps_form是在最终结账按钮后面生成的表单。如果您使用Firebug检查呈现的checkout按钮元素,您将看到该函数生成的表单。

我也有一个例子发布在我的博客上http://nmc-codes.blogspot.ca/2012/07/how-to-create-custom-ubercart-payment.html

至于no_gateway选项,这是我在ubercart模块中唯一能找到的引用它的代码:

if (empty($method['no_gateway'])) {
  $gateways = _uc_payment_gateway_list($id, TRUE);
  $options = array();
  foreach ($gateways as $gateway_id => $gateway) {
    $options[$gateway_id] = $gateway['title'];
  }
  if ($options) {
    $form['pmtable'][$id]['uc_payment_method_' . $id . '_checkout']['#title'] .= ' (' . t('includes %gateways', array('%gateways' => implode(', ', $options))) . ')';
  }
}

当你在admin/store/settings/payment 的支付方式管理列表中查看它时,它似乎没有什么作用,只是添加到了支付方式的标签/标题中