function mvf_field_instance_settings_form in Measured Value Field 7
Implements hook_field_instance_settings_form().
File
- ./
mvf.module, line 518 - Define a field type of measured value.
Code
function mvf_field_instance_settings_form($field, $instance) {
$form = array();
foreach ($field['settings']['meta_info'] as $subfield => $meta_info) {
$mocked_field = mvf_field_mockup($field, $subfield);
$mocked_instance = mvf_instance_mockup($field, $instance, $subfield);
// Checking if the module that defines a subfield wants to define any
// instance settings.
$extra = module_invoke($meta_info['module'], 'field_instance_settings_form', $mocked_field, $mocked_instance);
if (is_array($extra) && !empty($extra)) {
// Doing any customizations in the output of a sub field hook.
switch ($subfield) {
case 'unit':
// We have to add our custom validate function that will "repair"
// what brakes entity reference native validate function.
$extra['#element_validate'][] = 'mvf_entityreference_field_instance_settings_validate';
// We have to "save" original field definition array for
// our submit validation function.
$extra['#mvf'] = array(
'field' => $field,
);
$extra['#pre_render'][] = 'mvf_entityreference_field_instance_settings_pre_render';
break;
case 'value':
// Number module native 'min' and 'max' don't make sense in MVF,
// because min and max should be defined considering unit measure, and
// not only numeric value.
$extra['min']['#access'] = FALSE;
$extra['max']['#access'] = FALSE;
break;
}
$form[$subfield] = array(
'#type' => 'fieldset',
'#title' => t('@label Instance Settings', array(
'@label' => $meta_info['label'],
)),
'#collapsible' => TRUE,
) + $extra;
}
}
// Also defining some our proper MVF instance settings.
$form['mvf'] = array(
'#tree' => TRUE,
);
$form['mvf']['min'] = array(
'#type' => 'mvf_widget',
'#title' => t('Min'),
'#description' => t('The minimum value that should be allowed in this field. Leave blank for no minimum.'),
'#field' => $field,
'#instance' => $instance,
'#entity_type' => $instance['entity_type'],
'#default_value' => $instance['settings']['mvf']['min'],
);
$form['mvf']['max'] = array(
'#type' => 'mvf_widget',
'#title' => t('Max'),
'#description' => t('The maximum value that should be allowed in this field. Leave blank for no maximum.'),
'#field' => $field,
'#instance' => $instance,
'#entity_type' => $instance['entity_type'],
'#default_value' => $instance['settings']['mvf']['max'],
);
$form['mvf']['unit_suggesters_settings'] = array(
'#type' => 'mvf_unit_suggester',
'#title' => t('Unit suggestion'),
'#field' => $field,
'#instance' => $instance,
);
return $form;
}