Documentation for Units module
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
I will show you how to use Units module (the 7.x version of it).
Units module does not provide much of visible functionality itself, very likely you should enable this module only if there is another one depending on Units module. What Units module does provide is ability to manage measures and units. It also provides other modules with ability to convert some measurable number from one unit into another.
Measure is something, that can be measured in different units. Most of measures are some physical properties. For example: measure length is physical and can be measured in meters and inches.
Unit is something, in what you measure stuff. Units are grouped inside of measures. For example: measure length may have 2 units: meters and inches. Whereas measure weight may have another set of units: kilograms, grams, and pounds. Apparently, conversion is only possible between units of the same measure. We can't convert 5 meters into kilograms, right?
User Interface of Units Module
That's a little of background and terminology to make sure we are on the same page. Now let's proceed with what actually you can do via Units module. Let me begin by saying that Units consists of the following sub modules (you do not have to enable them all, only as many as you need to achieve your specific goal):
- Units (the core module, the rest of submodules will depend on this one): introduces all the necessary machinery for conversion between units
- Units UI: introduces administration UI for managing your measures and units. By "managing" I mean adding/removing/updating and so on.
- Common units and measures: practise revealed that majority of units and measures are very common from one website to another. Normally it's things like weight, length, area, volume, etc. Why would we force you to create them manually? We never should have, so we created this Units Default submodule. Once you've enabled it, you can choose a variety of standard measures and units. Those you've chosen will be added into your system. That way instead of manually adding these very common data (which is error prone to do it by hand, not to mention), now simply tick a few checkboxes and you are good to go.
- Units Currency: this one integrates Currency module. So the measure "Currency" becomes available and the currencies from Currency module become available as units in the Unit module. The conversion between different currencies is outsourced to the Currency module.
Working with Measures
If you have enabled Units UI module, then you should see a table of measures by following Structure -> Measures in your Drupal website. The table is pretty self-explanatory, go ahead and create some measure, if you do not have any yet. You will have to provide general info about the measure such as its name and description. Among other fields that form contains the field "Converting logic". Let me explain this one.
Most of the measures are linearly "convertible", what I mean by this: you kind of know that 1 meter is 100 centimetres, i.e. units are converted through a simple multiplication. This is exactly how "linear" works. When creating units you will provide a coefficient (factor) that will allow you to execute conversion between units whenever such need arises.
However, there are cases when units cannot be inter-converted via multiplication. For example: converting Celsius degrees (ºC) to Fahrenheit (ºF) is not linear, there is no such coefficient (factor), multiplying by which you will be able to convert numbers back and forth between them. If that's the case, then you will need another converting logic. Fear not, the Units Default submodule provides you with "Temperature" measure and its own converting logic that handles for you the necessary conversion between different temperature units. However, if you find yourself in the situation when you do need a new conversion logic, know that you can do it via CTools plugin. You may read more on it in the advanced help of Units module.
When you finished creating measure, you will have to add some units into it, otherwise the measure is just useless. In order to manage units that belong to particular measure, go to "manage units" link in the measures table.
Working with Units
When you go to manage units of any measure, you will see a similar overview table, where all existing units for that measure will be listed.
Again, it is pretty straightforward on how to add/delete/edit them. The only place, where I will call your attention is the "Factor" field. In case the measure you are working with has linear converting logic, the Factor value will be used for conversions between units. Let's suppose we are adding units into length measure. Length units are linearly convertible. When we create units we should pay attention to what Factors we supply for each one. I suggest to supply such factor, that converts value from the current unit into SI (or any other generally accepted) unit for that measure. Therefore for length we would have the following units and factors:
- Meter: factor = 1
- Centimeter: factor = 0.01
- Kilometer: factor = 1000
I think you figured out the point behind "Factor" field. I used the example of Length just to keep it simple, as I said above, if you need Length measure or any other common measure/units, check out Units Default before introducing them manually.
That's it. Using Units module you are able to set up measures, units, and facilities to execute conversions between different units. Other modules will use these functions in order to build some end-user functionality.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion