I need support to add units measures to unit api module, please let me know your comments

Comments

raspberryman’s picture

Status: Active » Closed (won't fix)

Heya jpvega_drupal,

You've got two options for adding units:

  • Option #1: Implement hook_unitsapi_alter() from your own module to add units.
  • Option #2: Create an issue with your requested units. The issue requires at least the unit name, plural name, symbol, conversion factor, and an URL to a credible source to verify the conversion factor. For the conversion factor, check the units.xml file for the common factor. For example, all Area conversions use square meters as their conversion factor.
cookieinc’s picture

Priority: Critical » Minor
Status: Closed (won't fix) » Needs review

Hey raspberryman,
Can you please quickly check my following code example, and if it's OK, what are your thoughts on including it in the documentation / project page in the section How To Add New Units? It might help other drupal newbies like myself.

Cheers, and thanks for the great module!

Create a new drupal module (tutorial) with the following function:

function YOUR_MODULE_NAME_unitsapi_load_alter(&$units) {
/** Add a kilopascal unit to the pressure category.
*   According to units.xml, the pressure category is based on pascals, so conversion factor will be 0.001
*/
$units['kilopascal'] = Array('singular' => 'kilopascal', 'plural' => 'kilopascals', 'symbol' => 'kPa', 'factor' => '0.001', 'kind' => 'pressure', 'source' => 'http://physics.nist.gov/Pubs/SP811/contents.html');
}
raspberryman’s picture

Assigned: Unassigned » raspberryman
Status: Needs review » Closed (fixed)

That looks great! I added this to the project's homepage.

I also added kilopascals to the supported units: http://drupalcode.org/project/unitsapi.git/commitdiff/654bb05