function mvf_unit_suggest in Measured Value Field 7
Request a suggested unit on a particular items of MVF field.
Parameters
array $items: Array of items for which to get a suggested unit
array $field: Field definition array of the field for which to get a suggested unit. This field must be of MVF types, of course
array $instance: Field instance definition array that corresponds to $field
object $entity: Fully loaded entity for which to get a suggested unit
string $view_mode: If you want to retrieve unit suggestion on a specific view mode of the provided MVF field, then provide it here. You may skip this argument and then suggested unit will be based on general MVF instance settings
array $skip_suggestions: In case you want to explicitly ignore some suggestions, provide them here and the function will not consider them. You can supply here specific IDs of 'units_unit' entities. However, the most useful elements of this array would be the constants MVF_UNIT_*
Return value
int Suggested unit for the provided input arguments. It will be either ID of 'units_unit' entity or any constant of MVF_UNIT_*
2 calls to mvf_unit_suggest()
- mvf_field_formatter_prepare_view in ./
mvf.module - Implements hook_field_formatter_prepare_view().
- _mvf_widget_process in ./
mvf.module - Process function for form element type 'mvf_widget'.
File
- ./
mvf.module, line 2036 - Define a field type of measured value.
Code
function mvf_unit_suggest($items, $field, $instance, $entity, $view_mode = NULL, $skip_suggestions = array()) {
$skip_suggestions[] = MVF_UNIT_UNKNOWN;
$unit_suggesters = mvf_unit_suggesters_info($field, $instance, $view_mode);
$output_unit = MVF_UNIT_UNKNOWN;
foreach ($unit_suggesters as $v) {
if ($v['settings']['enable'] && ($function = ctools_plugin_get_function($v['plugin'], 'suggest unit callback'))) {
$output_unit = $function($items, $field, $instance, $entity, $instance['entity_type'], $v['settings'], $v['plugin']);
if (!in_array($output_unit, $skip_suggestions)) {
break;
}
}
}
return $output_unit;
}