I think this is a bug.

There are examples In Payment submodule in api file:

<?php
function CALLBACK_commerce_payment_method_settings_form($settings = NULL) {
  // No example.
}

//...

function CALLBACK_commerce_payment_method_redirect_form($form, &$form_state, $order, $payment_method) {
  // No example.
}
?>

But implementation of these callbacks in my module don't work.
I have to change callback implementations like this (removing "commerce_payment_method" from functions names):

<?php
function CALLBACK_settings_form($settings = NULL) {
  // No example.
}

//...

function CALLBACK_redirect_form($form, &$form_state, $order, $payment_method) {
  // No example.
}
?>

I have not set callbacks in hook_commerce_payment_method_info, so default callback function names are used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Category: bug » support
Status: Active » Closed (works as designed)

Well, technically speaking, we wouldn't call the base fragment "CALLBACK_" either, as the whole thing is really the callback (e.g. commerce_paypal_wps_redirect_form). The idea is that this is just the payment method redirect form callback, with the name really being whatever you set the callback name to. It's a little confusing, but there isn't really a "correct" notation here; best to just reference an existing payment method module when you need pointers like these.

tomas.teicher’s picture

there isn't really a "correct" notation

Si I should not use default naming CALLBACK_BASE_settings_form without settings callback explicitily in HOOK_commerce_payment_method_info?

I have noticed that some modules use this convention without explicitely define callback names in hook_commerce_payment_method_info.

If I can use "base" parameter from HOOK_commerce_payment_method_info function, maybe making example callback names uppercase would be more obvious

for example
CALLBACK_COMMERCE_PAYMENT_METHOD_settings_form

I spend a little while, while I have found out, why my own callback don't work.

rszrama’s picture

The way a callback works, it's the base with the name of the callback appended. We default the base to the name of the payment method, but you can set it to whatever you want. Thus in the PayPal WPS module, we define the base as commerce_paypal_wps so we have callbacks like commerce_paypal_wps_redirect_form().

marcoscano’s picture

Issue summary: View changes
Priority: Normal » Minor
Status: Closed (works as designed) » Needs review
FileSize
941 bytes

This also confused me, once we intuitively assume that what is in the "base" property of hook_commerce_payment_method_info() is going to replace only the part "CALLBACK" in the callback names...

Perhaps just adding a more detailed explanation in the hook documentation is enough to avoid this confusion? A suggestion is in the patch attached.

Status: Needs review » Needs work

The last submitted patch, 4: Improving-documentation-base-2073733-4.patch, failed testing.