Closed (fixed)
Project:
Units API
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Dec 2011 at 13:52 UTC
Updated:
1 Dec 2012 at 17:00 UTC
Using the result conversion hooks I stumbled upon an error in the convert function and the table generate function.
When the factor is an array it will generate a 500 error.
So for the function _unitsapi_key_table() replace if ($curr_kind == 'temperature') with if (is_array($unit['factor']))
and for the function unitsapi_convert() replace the switch statement with
$result=0;
// Execute the conversion factors differently based on the kind. For example, temperature needs to be executed differently.
switch ($units[$from]['kind']) {
case 'temperature':
$result = _unitsapi_convert_temperature($value, $units[$to]['factor'][$from]);
break;
}
if(!is_array($units[$from]['factor']) && !is_array($units[$to]['factor']))
{
$from_si = $units[$from]['factor'];
$to_si = $units[$to]['factor'];
$from_convert = $value * $from_si;
$result = $from_convert / $to_si;
}and perhaps you can also provide all the arguments in the alter_hook if someone wishes to overload the function
$args = func_get_args();
// Allow other modules to modify conversion results.
drupal_alter('unitsapi_result', $result_array, $args);I also attached a screenshot that maybe will explain why this is necessary :-) for the function overloading I need to provide the from key as a parameter.
| Comment | File | Size | Author |
|---|---|---|---|
| Selection_004.png | 51.3 KB | bugster |
Comments
Comment #1
raspberryman commentedThanks for this feedback! I modified the units.xml to now support multiple factors as a given, and updated the module to respect that change. See: http://drupalcode.org/project/unitsapi.git/commit/69044a7