You are here

function entity_metadata_field_default_property_callback in Entity API 7

Callback to add in property info defaults per field instance.

See also

entity_metadata_field_entity_property_info()

1 string reference to 'entity_metadata_field_default_property_callback'
entity_metadata_field_entity_property_info in modules/field.info.inc
Implements hook_entity_property_info() on top of field module.

File

modules/field.info.inc, line 50
Provides info for fields.

Code

function entity_metadata_field_default_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
  if (!empty($field_type['property_type'])) {
    if ($field['cardinality'] != 1) {
      $field_type['property_type'] = 'list<' . $field_type['property_type'] . '>';
    }

    // Add in instance specific property info, if given and apply defaults.
    $name = $field['field_name'];
    $property =& $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
    $instance += array(
      'property info' => array(),
    );
    $property = $instance['property info'] + array(
      // Since the label will be exposed via hook_token_info() and it is not
      // clearly defined if that should be sanitized already we prevent XSS
      // right here (field labels are user provided text).
      'label' => filter_xss_admin($instance['label']),
      'type' => $field_type['property_type'],
      'description' => t('Field "@name".', array(
        '@name' => $name,
      )),
      'getter callback' => 'entity_metadata_field_property_get',
      'setter callback' => 'entity_metadata_field_property_set',
      'access callback' => 'entity_metadata_field_access_callback',
      'query callback' => 'entity_metadata_field_query',
      'translatable' => !empty($field['translatable']),
      // Specify that this property stems from a field.
      'field' => TRUE,
      'required' => !empty($instance['required']),
    );

    // For field types of the list module add in the options list callback.
    if (strpos($field['type'], 'list') === 0) {
      $property['options list'] = 'entity_metadata_field_options_list';
    }
  }
}