function relation_add_get_relation in Relation add 7
Entity property info getter callback for the relations.
1 string reference to 'relation_add_get_relation'
File
- ./
relation_add.module, line 1319 - Relation Add module file.
Code
function relation_add_get_relation($entity, array $options, $property_name, $entity_type, $info) {
$field = field_info_field($property_name);
$langcode = field_language($entity_type, $entity, $property_name, isset($options['language']) ? $options['language']->language : NULL);
$values = array();
if (isset($entity->{$property_name}[$langcode])) {
foreach ($entity->{$property_name}[$langcode] as $delta => $data) {
// Wrappers do not support multiple entity references being revisions or
// not yet saved entities. In the case of a single reference we can return
// the entity object though.
if ($field['cardinality'] == 1) {
$values[$delta] = relation_load($data);
}
elseif (isset($data['rid'])) {
$values[$delta] = $data['rid'];
}
}
}
// For an empty single-valued field, we have to return NULL.
return $field['cardinality'] == 1 ? $values ? reset($values) : NULL : $values;
}