function mvf_field_update_instance in Measured Value Field 7
Implements hook_field_update_instance().
File
- ./
mvf.module, line 1054 - Define a field type of measured value.
Code
function mvf_field_update_instance($instance, $prior_instance) {
$field_map = field_info_field_map();
if (in_array($field_map[$instance['field_name']]['type'], mvf_field_types())) {
// Notify each unit suggester if its status has changed.
$field = field_info_field($instance['field_name']);
$measure = mvf_measure_extract($field);
$unit_suggesters = mvf_get_unit_suggester();
$view_modes = array_unique(array_merge(array_keys($instance['display']), array_keys($prior_instance['display'])));
$view_modes[] = NULL;
foreach ($view_modes as $view_mode) {
foreach ($unit_suggesters as $unit_suggester) {
$statuses = array(
'prior' => array(
'instance' => $prior_instance,
'status' => FALSE,
),
'current' => array(
'instance' => $instance,
'status' => FALSE,
),
);
foreach ($statuses as $k => $v) {
if ($view_mode && !isset($v['instance']['display'][$view_mode])) {
$statuses[$k]['status'] = FALSE;
}
else {
$statuses[$k]['status'] = mvf_unit_suggester_info($unit_suggester, $field, $v['instance'], $view_mode);
$statuses[$k]['status'] = $statuses[$k]['status']['enable'];
}
}
if ($statuses['prior']['status'] != $statuses['current']['status']) {
$callback_name = $statuses['current']['status'] ? 'enabled callback' : 'disabled callback';
$function = ctools_plugin_get_function($unit_suggester, $callback_name);
if ($function) {
$settings = $statuses['current']['status'] ? mvf_unit_suggester_info($unit_suggester, $field, $statuses['current']['instance'], $view_mode) : mvf_unit_suggester_info($unit_suggester, $field, $statuses['prior']['instance'], $view_mode);
$function($measure, $field, $instance, $view_mode, $settings, $unit_suggester);
}
}
}
}
}
}