Closed (fixed)
Project:
Units API
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
6 Dec 2010 at 08:52 UTC
Updated:
2 Apr 2011 at 22:27 UTC
Jump to comment: Most recent file
I created a patch for hooking on the conversion method.
If the factor field of to or from is an array then use an other method for the unit conversion (like the temperature fields).
This way modules can extend the units api with their own units and conversion methods.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | unitsapi.patch | 1.22 KB | bugster |
| unitsapi.patch | 2.74 KB | bugster |
Comments
Comment #1
raspberryman commentedHeya bugster - Thanks for the idea! I very much agree.
I implemented it in a slightly different way: hook_unitsapi_result_alter(&$result) will give you an array with the original conversion value, the conversion result, and the full array of data for the relevant units from the XML, and let you alter any of these fields before the conversion is over.
Commit in http://drupal.org/cvs?commit=489122
Comment #2
bugster commentedNice work, cleaner implementation!
I added a patch, so you could add more arguments to the unitsapi_convert function, those arguments go with the drupal_alter function. (func_get_args()) This way you are extremely flexible.
and if the factor is an array then output them like you do with the temperatures.
Comment #3
bugster commentedI also think you need to test if factor of from and to is numeric, it is possible that someone puts something different in there, like temperature.
else you can get an illegal operand error.
If those factors are not numeric you may assume they are custom, and correctly implemented in alter result;
You can test this if you remove the switch statement and implement the temperature conversion using the unitsapi_unitsapi_result_alter() function :)
Comment #4
raspberryman commentedThanks for your great ideas, bugster!
The following two commits add these features:
http://drupalcode.org/project/unitsapi.git/commitdiff/0256ffb
http://drupalcode.org/project/unitsapi.git/commitdiff/48335a6