UnitsAPI D8
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
This is an enhanced, D8 version of the UnitsAPI module.
https://www.drupal.org/project/unitsapi
Units API converts between various weights and measurements. The conversion uses the International System of Units (SI) conversion factors. Where possible, these conversion factors are those provided by the U.S. National Institute of Standards and Technology (NIST) Special Publication 811, 2008 Edition. If the NIST does not provide the conversion factor, other sources may be used as long as the work is GPL compatible.
The main unit conversion API call in this module is
DrupalunitsapiConverter::convertUnit($quantity, $from_unit, $to_unit, $log_input = FALSE), which returns a DrupalunitsapiMeasurement object with containing lots of useful methods for printing, getting info about the unit, and other utilities. It can also be used as a string.
The Drupal 8 version of the module differs from the D7 version by making units YAML discovery plugins and the properties (for example length, mass, temperature etc) annotation discovery plugins.
Making the properties plugin classes allows comple conversions possible. This version of UnitsAPI allows one to calculate measurements of differing units.
createDerivedMeasurement(array $base_values, $to_unit, $log_input = FALSE) will convert base units into derived units, for example mass and volume to density.
calcBaseMeasurement($property_quantity, $property_unit, array $base_values, $to_unit = NULL, $log_input = FALSE) allows the reverse of this; calculating a missing base value from a derived property. For example, getting the force when given pressure and area measurements.
calculateMeasurementFromUnits(array $unit_data_list, $return_type = NULL) will take a list of units and give back whatever can be done with them. For example, feeding it a length and an area will return an array of measurements with a length that makes length * length = area true, and the volume of area * length.
Example code usage coming soon.
This module is only an API and does not have an user interface.
