hook_line_item() require from developer to create a 'callback' function (description from api docs: "Name of the line item's callback function, called for various operations"). Creating my own module I decide to overwrite my line item default form on order edit page. And there is no problem due to available function uc_order_add_line_item_form(). With this function if you defined 'form' option then you can return your custom $form array with all fields you needed. The problem is starting when you trying to validate or submit your form data with following options in inside your custom callback, 'validate' & 'submit'. They both are fired by uc_order_add_line_item_form_validate() and uc_order_add_line_item_form_submit() functions.

It looks like someone make mistake because they passing only orderID to your callback nothings more. Without it as can images is hard to validate or submit anything so it's seems for me this functions are useless until you pass ALL values from $form_state.

Functions to look:

I hope this make sense if not please let me know. If there is other way to check submitted values from my custom form then please explain me how to do it.

I've create a patch so please someone to test it and commit to branch. Cheers.

Comments

sobi3ch’s picture

sobi3ch’s picture

Status: Active » Needs review
sobi3ch’s picture

Issue summary: View changes

+update

longwave’s picture

I didn't even know these 'form', 'validate', and 'submit' callbacks were available, they aren't used in core and I guess they aren't used in contrib either as nobody has noticed this before.

Should we just pass all of $form_state, not just the 'values' key? Would it be useful to have $order available in the callback? And maybe $form for consistency? The reason I ask about $order is that the callback parameters are ($op, $order) by default, and if possible I don't think we should pass $order sometimes and $form_state in other situations.

sobi3ch’s picture

Haha I was looking at this code for good couple minutes thinking this doesn't make sense. Then I realize this is a bug :).

Should we just pass all of $form_state, not just the 'values' key?

Yeap, good idea.

Would it be useful to have $order available in the callback? (..) The reason I ask about $order is that the callback parameters are ($op, $order) by default, and if possible I don't think we should pass $order sometimes and $form_state in other situations.

Sorry, can't agree. If you check hook_line_item() documentation then you can see $op 'load' and 'dispaly' are actually $order object but not for 'cart-preview'. In this case you have: (..) an array of of product objects for the items in the cart. If you need $order object then you can always load it by uc_order_load($form_state['order_id']);. And it's not always needed so then it will be just additional cost.

And maybe $form for consistency?

Sounds good.

To sum up I think to pass $form as $arg1 and $form_state as $arg2.
Moving..

your_module_line_item_callback($op, &$arg1) {}
..
$func('validate', $form_state['values']['order_id']);
$func('submit', $form_state['values']['order_id']);

to something like this:

your_module_line_item_callback($op, &$arg1, &$arg2 = NULL) {}
..
$func('validate', $form, $form_state);
$func('submit', $form, $form_state);

I'll try to submit new patch ASAP. Cheers.

sobi3ch’s picture

Status: Needs review » Needs work

Need to create a patch

sobi3ch’s picture

Patch.

sobi3ch’s picture

So.. anybody can review it? Thanks.

sobi3ch’s picture

Title: uc_order_add_line_item_form callback validate & submit functions doesn't pass values from $form_state (only orderID) » uc_order_add_line_item_form validate & submit callbacks doesn't pass values from $form_state (only orderID)
longwave’s picture

Status: Needs review » Fixed

As nobody has spotted this before, and these callbacks would be mostly useless without $form_state, I think it is safe to make this API change now. Committed to both branches.

sobi3ch’s picture

thx

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

+link to api docs