function mvf_unit_suggesters_info in Measured Value Field 7
Collect information about available unit suggesters and their settings.
Parameters
array $field: Field API field definition array of MVF field
array $instance: Field API instance definition array of MVF field
string $view_mode: Optional name of the view mode. If you want to retrieve unit suggesters for a specific view mode of a MVF instance, then provide this view mode here. If it is omitted, a list of generally configured unit suggesters for this MVF instance will be returned
Return value
array Array of information about available unit suggesters and their settings for provided $field and $instance. Array will be sorted by weight of unit suggesters, i.e. elements will go in the order, in which they are supposed to suggest output units for provided $field and $instance. Values of this array will have the following structure:
- plugin: (array) CTools plugin definition array of this unit suggester
- settings: (array) Array of settings for provided $field and $instance.
This array will have the following structure:
- enable: (bool) Whether this unit suggester is enabled for provided $field and $instance
- weight: (int) Weight (priority) at which this unit suggester should be asked to suggest output unit for provided $field and $instance
- ... Different unit suggesters might keep any additional settings here, which varies on per unit suggester basis
3 calls to mvf_unit_suggesters_info()
- mvf_field_delete_instance in ./
mvf.module - Implements hook_field_delete_instance().
- mvf_unit_suggest in ./
mvf.module - Request a suggested unit on a particular items of MVF field.
- _mvf_unit_suggester_process in ./
mvf.module - Form API process function for 'mvf_unit_suggester' form element.
File
- ./
mvf.module, line 1644 - Define a field type of measured value.
Code
function mvf_unit_suggesters_info($field, $instance, $view_mode = NULL) {
$unit_suggester_info = array();
$plugins = mvf_get_unit_suggester();
$measure = mvf_measure_extract($field);
$unit_suggester_settings = $instance['settings']['mvf']['unit_suggesters_settings'];
if ($view_mode && isset($instance['display'][$view_mode]['settings']['mvf']['override']) && $instance['display'][$view_mode]['settings']['mvf']['override']) {
$unit_suggester_settings = $instance['display'][$view_mode]['settings']['mvf']['unit_suggesters_settings'];
}
foreach ($plugins as $plugin) {
if ($plugin['applicable callback'] !== TRUE) {
$function = ctools_plugin_get_function($plugin, 'applicable callback');
$is_applicable = $function && $function($measure, $field, $instance, $plugin);
}
else {
$is_applicable = TRUE;
}
if ($is_applicable) {
$settings = isset($unit_suggester_settings[mvf_unit_suggesters_settings_name($plugin)]) ? $unit_suggester_settings[mvf_unit_suggesters_settings_name($plugin)] : array(
'enable' => FALSE,
'weight' => 0,
);
$unit_suggester_info[] = array(
'plugin' => $plugin,
'settings' => $settings,
);
}
}
// Sorting by weight all available unit suggesters.
usort($unit_suggester_info, '_mvf_unit_suggesters_info_sort');
return $unit_suggester_info;
}