function addtocal_field_get_value in Add to Cal 7
Return the value of a field
Parameters
$entity_type:
$entity:
$field_name:
Return value
string
1 call to addtocal_field_get_value()
- addtocal_extract_event_info in ./
addtocal.module - Return event information in an associative array based on a given entity.
File
- ./
addtocal.module, line 360 - addtocal.module General functions and hook implementations.
Code
function addtocal_field_get_value($entity_type, $entity, $field_name) {
if (!empty($field_name)) {
if (!$field_name['tokenized']) {
// Unless tokenization has been applied,
$field_name = $field_name['field'];
// just use the raw content of the field.
$value = field_get_items($entity_type, $entity, $field_name);
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'addressfield') {
$address = $value[0];
$string = '';
if (!empty($address['thoroughfare'])) {
$string .= $address['thoroughfare'] . ' ';
}
if (!empty($address['premise'])) {
$string .= $address['premise'] . ', ';
}
if (!empty($address['locality'])) {
$string .= $address['locality'] . ', ';
}
if (!empty($address['administrative_area'])) {
$string .= $address['administrative_area'] . ' ';
}
if (!empty($address['postal_code'])) {
$string .= $address['postal_code'] . ', ';
}
if (!empty($address['country'])) {
$string .= $address['country'];
}
$output = $string;
}
else {
$replace_strings = array(
' ' => '',
'<br />' => '\\n',
PHP_EOL => '\\n',
);
$output = $value[0]['value'];
foreach ($replace_strings as $search => $replace) {
$output = str_replace($search, $replace, $output);
}
}
}
else {
$output = token_replace($field_name['tokenized'], array(
'node' => $entity,
), array(
'clear' => TRUE,
));
}
return $output;
}
else {
return '';
}
}