This has a number of advantages:
- easier to test which fields to act on
- easier to get hold of the right form element
- code is easier to read because instead of $form[$key][$form[$key]['#language']][$delta]
it's just $element
- code is easier to read because of fewer loops
Downside:
- function is called once for each price field on the form
- options list of tax types is re-built each time
- requires Drupal core 7.8 or later
I don't think the first two of those are a big problem as performance in an edit form is not a huge concern; furthermore I'm testing this with 3 price fields and I don't see an impact at all
Comment | File | Size | Author |
---|---|---|---|
#6 | 1791226.6.commerce.tax-price-hook_field_widget_form_alter.patch | 5.68 KB | joachim |
#1 | 1791226.commerce.tax-price-hook_field_widget_form_alter.patch | 5.23 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedComment #2
rszrama CreditAttribution: rszrama commentedHmm, do you have any ideas on the best way to document the Drupal 7.8 requirement? I'm ok with it, since we've had multiple security releases since then, but .info files can only specify major versions. Should we just add a hook_requirements() to commerce_tax.install?
Comment #3
joachim CreditAttribution: joachim commentedIt's not that clear from http://drupal.org/node/542202 how to do this with core modules, but it does seem to work.
I just chucked this into one of my custom module:
and the module admin page says:
Comment #4
rszrama CreditAttribution: rszrama commentedHmm, I suppose that would fail though if Drupal were checked out from Git? Would even Git Deploy solve this in that situation?
If this hook was only added in Drupal 7.8, maybe there's a way we can check for it directly? Perhaps some other core implementation of the hook?
Comment #5
joachim CreditAttribution: joachim commentedNot sure what you'd do about git, but admin_menu uses this already:
... so we'd be in good company :)
Comment #6
joachim CreditAttribution: joachim commentedHere's a rerolled patch with that in.
Comment #7
rszrama CreditAttribution: rszrama commentedOk, so bojanz reminded me that we've actually had a dependency on Drupal 7.4 since Commerce 1.2 because of some uninstallation changes, and at the time we released 1.2 I was comfortable enough leaving out the Admin Menu style notification because there had been security releases since Drupal 7.4 anyways. I'm just going to follow that model here on the off chance that making the Drupal 7.8 dependency enforced via the .info file screws up someone deploying from Git. Probably few people, but even fewer people should be on Drupal 7.8 since it was released in August 2011 and two security updates have been released since then.
I also added a drupal_static() implementation to cache the list of inclusive types. Then I realized that this was questionably more performant, because we're trading array iteration time for what amounts to duplicate information stored in memory. The tax type array is already statically cached, so we're not in danger of additional queries or anything... so I took out the static implementation I added in. ; )
Committed, all creds to joachim. : )
Comment #8.0
(not verified) CreditAttribution: commentedUpdated issue summary.