You are here

function mvf_field_info in Measured Value Field 7

Same name and namespace in other branches
  1. 6 mvf.module \mvf_field_info()

Implements hook_field_info().

1 call to mvf_field_info()
mvf_field_types in ./mvf.module
Return an array of field types that are provided by MVF.

File

./mvf.module, line 69
Define a field type of measured value.

Code

function mvf_field_info() {
  $field_info = array();

  // Collecting data from modules that define our sub fields.
  $value = module_invoke(MVF_MODULE_VALUE, 'field_info');
  $unit = module_invoke(MVF_MODULE_UNIT, 'field_info');

  // We narrow down a list of field types eligible for units sub field. As we
  // currently only support entityreference field type.
  $unit = array(
    'entityreference' => $unit['entityreference'],
  );
  foreach ($value as $value_field_type => $value_settings) {
    foreach ($unit as $unit_field_type => $unit_settings) {

      // We hard code 'target_type' setting of unit subfield to be 'units_unit'.
      $unit_settings['settings']['target_type'] = 'units_unit';
      $field_info['mvf_' . $value_field_type . '_' . $unit_field_type] = array(
        'label' => t('Measured @type', array(
          '@type' => $value_settings['label'],
        )),
        'settings' => array(
          'value' => isset($value_settings['settings']) ? $value_settings['settings'] : array(),
          'unit' => isset($unit_settings['settings']) ? $unit_settings['settings'] : array(),
          'meta_info' => array(
            'value' => array(
              'field_type' => $value_field_type,
              'widget' => $value_settings['default_widget'],
              'formatter' => $value_settings['default_formatter'],
              'module' => MVF_MODULE_VALUE,
              'label' => t('Value'),
              'not_supported_widgets' => array(),
            ),
            'unit' => array(
              'field_type' => $unit_field_type,
              'widget' => $unit_settings['default_widget'],
              'formatter' => $unit_settings['default_formatter'],
              'module' => MVF_MODULE_UNIT,
              'label' => t('Unit Measure'),
              // We can't support these widgets because entityreference module
              // tries to pull up field settings by field name, in our case
              // it won't be able to find its settings in the structure how we
              // keep it in MVF.
              'not_supported_widgets' => array(
                'entityreference_autocomplete',
                'entityreference_autocomplete_tags',
              ),
            ),
          ),
        ),
        'instance_settings' => array(
          'value' => isset($value_settings['instance_settings']) ? $value_settings['instance_settings'] : array(),
          'unit' => isset($unit_settings['instance_settings']) ? $unit_settings['instance_settings'] : array(),
          'mvf' => array(
            'min' => array(
              mvf_subfield_to_column('value') => NULL,
              mvf_subfield_to_column('unit') => NULL,
            ),
            'max' => array(
              mvf_subfield_to_column('value') => NULL,
              mvf_subfield_to_column('unit') => NULL,
            ),
            'unit_suggesters_settings' => array(),
          ),
        ),
        'default_widget' => 'mvf_widget_default',
        'default_formatter' => 'mvf_formatter_default',
        'property_type' => 'mvf_' . $value_field_type . '_' . $unit_field_type,
        'property_callbacks' => array(
          'mvf_property_info_callback',
        ),
      );
    }
  }
  return $field_info;
}