You are here

function computed_field_entity_property_callback in Computed Field 7

Callback to setup Entity API's field properties.

1 string reference to 'computed_field_entity_property_callback'
computed_field_field_info in ./computed_field.module
Implements hook_field_info().

File

./computed_field.module, line 89
Functionality for the computed field.

Code

function computed_field_entity_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $property_types = array(
    'int' => 'integer',
    'float' => 'decimal',
    'numeric' => 'decimal',
    'varchar' => 'text',
    'text' => 'text',
    'longtext' => 'text',
  );
  if (isset($field['columns']['value'], $property_types[$field['columns']['value']['type']])) {

    // Entity API's defaults are pretty good so set the property_type and let them do the work for us.
    $field_type['property_type'] = $property_types[$field['columns']['value']['type']];
    entity_metadata_field_default_property_callback($info, $entity_type, $field, $instance, $field_type);

    // The only thing is that a setter doesn't make sense, so let's disable it.
    $property =& $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
    unset($property['setter callback']);
  }
}