Implementing a custom unit suggester is as easy as defining a CTools plugin in the code of your module. The owner of plugin is mvf module, the plugin name is unit_suggesters. You can find an example of such plugin implementation in the plugins folder of mvf module. The parameters of unit_suggesters plugin should be:
title
Required. The human readable name of your unit suggester.
description
A brief description of your unit suggester. Try to explain how exactly the unit suggestion happens in your plugin.
applicable callback
Required. Either TRUE (denotes "always applies") or name of the function that will be responsible to determine whether your unit suggester applies to a particular field instance. This function will receive the following input arguments:
  1. $measure: (object) Fully loaded 'units_measure' entity, on which the MVF field is set up
  2. $field: (array) Field API field definition array of the MVF field in question
  3. $instance: (array) Field API instance definition array of the MVF field in question
  4. plugin: (array) cTools plugin definition array of your unit suggester plugin
Your function should analyze the input arguments and return TRUE if your unit suggester applies to the provided $measure, $field, and $instance. Otherwise return FALSE.
enabled callback
Name of the function. It will be invoked when your unit suggester is enabled in any instance. You are welcome to do any initialization routines in here. This function will receive the following input arguments:
  1. $measure: (object) Fully loaded 'units_measure' entity, on which the MVF field is set up
  2. $field: (array) Field API field definition array of MVF field
  3. $instance: (array) Field API instance definition array of MVF field
  4. $view_mode: (string) View mode (key in $instance['display'] array) in which your unit suggester was enabled. It may be NULL, if your unit suggester is enabled on the instance level
  5. $settings: (array) Array of currently stored suggester settings in the provided $instance
  6. $plugin: (array) cTools plugin definition array of your unit suggester plugin
disabled callback
Name of the function. It will be invoked when your unit suggester is disabled in any instance. You are welcome do to any destruction routines in here. This function will receive the following input arguments:
  1. $measure: (object) Fully loaded 'units_measure' entity, on which the MVF field is set up
  2. $field: (array) Field API field definition array of MVF field
  3. $instance: (array) Field API instance definition array of MVF field
  4. $view_mode: (string) View mode (key in $instance['display'] array) in which your unit suggester was disabled. It may be NULL, if your unit suggester is disabled on the instance level
  5. $settings: (array) Array of currently stored suggester settings in the provided $instance
  6. $plugin: (array) cTools plugin definition array of your unit suggester plugin
settings form callback
Name of the function. This function will generate form elements that represent settings form of your unit suggester. This function will receive the following input arguments:
  1. $measure: (object) Fully loaded 'units_measure' entity, on which the MVF field is set up
  2. $field: (array) Field API field definition array of MVF field
  3. $instance: (array) Field API instance definition array of MVF field
  4. $settings: (array) Array of currently stored suggester settings in the provided $instance, you are encouraged to use it as source of #default_value for the form elements you are defining in this function
  5. $plugin: (array) cTools plugin definition array of your unit suggester plugin
The function should return array - form elements that define settings of your unit suggester. Values, submitted into the returned form elements will be stored in $settings
suggest unit callback
Required. Name of the function that provides actual unit suggesting. This function will receive the following input arguments:
  1. $items: (array) Array of MVF field items for which you are requested to suggest output unit. This array may be empty, for example, when default pre-entered unit is being determined for a MVF widget.
  2. $field: (array) Field API field definition array of MVF field
  3. $instance: (array) Field API instance definition array of MVF field
  4. $entity: (object) Fully loaded entity, for which you are requested to suggest output unit
  5. $entity_type: (string) Entity type of $entity
  6. $settings: (array) Array of currently stored suggester settings in the provided $instance, you are encouraged to use it when deciding what output unit to suggest
  7. $plugin: (array) cTools plugin definition array of your unit suggester plugin
The function should return ID of a 'units_unit' entity, that you suggest as output unit. Two additional constants can be used as output here: