Closed (fixed)
Project:
Ubercart
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 May 2011 at 10:42 UTC
Updated:
6 Jul 2011 at 14:11 UTC
Jump to comment: Most recent file
hook_uc_cart_pane(), hook_uc_checkout_pane() and hook_uc_order_pane() specify unique IDs for each pane, but these are not used as the array key, making it more difficult than should be necessary to find a specific pane from code.
As an example I suggest we change:
$panes[] = array(
'id' => 'cart',
'callback' => 'uc_checkout_pane_cart',
'title' => t('Cart contents'),
'desc' => t("Display the contents of a customer's shopping cart."),
'weight' => 1,
'process' => FALSE,
'collapsible' => FALSE,
);
to
$panes['cart'] = array(
'callback' => 'uc_checkout_pane_cart',
'title' => t('Cart contents'),
'desc' => t("Display the contents of a customer's shopping cart."),
'weight' => 1,
'process' => FALSE,
'collapsible' => FALSE,
);
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 1168280-hook_uc_order_state-dx.patch | 5.85 KB | longwave |
| #11 | 1168280-hook_uc_line_item-dx.patch | 6.93 KB | longwave |
| #10 | 1168280-payment-methods-and-gateways.patch | 30.36 KB | longwave |
| #5 | 1168280-hook_uc_cart_pane-dx.patch | 6.71 KB | longwave |
| #4 | 1168280-hook_uc_cart_pane-dx.patch | 6.46 KB | longwave |
Comments
Comment #1
longwavehook_uc_payment_method() and hook_uc_payment_gateway() could similarly be improved this way.
I don't see why this couldn't be backward compatible, we can just ensure $key == $value['id'] after running module_invoke_all().
Comment #2
tr commentedhook_uc_shipping_method() implementations have an 'id' key *and* an array key. By convention they are identical . For example:
We could do this same thing for the five hooks mentioned above without having to worry about doing anything for backwards compatibility.
Comment #3
longwaveSample patch for hook_uc_cart_pane(). The usefulness of this can be summarized by looking at the changes in the hook_uc_cart_pane_alter() example, from:
to
Comment #4
longwaveLet's try attaching that again.
Comment #5
longwaveThe static cart pane cache seems useless, so this patch removes that too.
Comment #6
tr commentedSo you don't like the idea of just doing
so we don't have to worry about unintended consequences of removing 'id' ?
Comment #7
longwaveThere seems little point in asking developers to specify each id twice in the hook.
Old
$panes[] = array(...)declarations will have their key explicitly set. New declarations with no 'id' member will be given one, so code expecting the old style will still work.Comment #8
longwaveCommitted the above patch plus similar patches for hook_uc_checkout_pane() and hook_uc_order_pane().
Along with payment methods/gateways, I also noticed that hook_uc_line_item() could be improved in the same way, as could hook_uc_order_state() (although that last one is very minor).
Comment #9
tr commentedCommit http://drupalcode.org/project/ubercart.git/commitdiff/77800bb introduced a bug, now fixed: #1186520: Notice: Undefined variable: i in uc_cart_filter_checkout_panes()
Comment #10
longwaveCommitted the attached patchset which changes hook_uc_payment_method() and hook_uc_payment_gateway() to be keyed by ID.
Comment #11
longwavehook_uc_line_item patch attached.
Comment #12
longwaveCommitted #11 along with the attached patch for hook_uc_order_state(), which I think means this can be marked fixed.