You are here

function entity_metadata_field_property_get in Entity API 7

Callback for getting field property values.

1 string reference to 'entity_metadata_field_property_get'
entity_metadata_field_default_property_callback in modules/field.info.inc
Callback to add in property info defaults per field instance.

File

modules/callbacks.inc, line 443
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_field_property_get($entity, array $options, $name, $entity_type, $info) {
  $field = field_info_field($name);
  $columns = array_keys($field['columns']);
  $langcode = isset($options['language']) ? $options['language']->language : LANGUAGE_NONE;
  $langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode, TRUE);
  $values = array();
  if (isset($entity->{$name}[$langcode])) {
    foreach ($entity->{$name}[$langcode] as $delta => $data) {
      $values[$delta] = $data[$columns[0]];
      if ($info['type'] == 'boolean' || $info['type'] == 'list<boolean>') {

        // Ensure that we have a clean boolean data type.
        $values[$delta] = (bool) $values[$delta];
      }
    }
  }

  // For an empty single-valued field, we have to return NULL.
  return $field['cardinality'] == 1 ? $values ? reset($values) : NULL : $values;
}