function ds_render_field in Display Suite 7
Same name and namespace in other branches
- 7.2 ds.module \ds_render_field()
Render a field.
1 string reference to 'ds_render_field'
- ds_ds_fields_info in ./
ds.ds_fields_info.inc - Implements hook_ds_fields_info().
File
- ./
ds.module, line 1164 - Display Suite core functions.
Code
function ds_render_field($field) {
$output = '';
$settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : array();
$settings += $field['properties']['default'];
// Basic string.
if (isset($settings['link text'])) {
$output = t($settings['link text']);
}
elseif (isset($field['properties']['entity_render_key']) && isset($field['entity']->{$field['properties']['entity_render_key']})) {
if ($field['entity_type'] == 'user' && $field['properties']['entity_render_key'] == 'name') {
$output = format_username($field['entity']);
}
else {
$output = $field['entity']->{$field['properties']['entity_render_key']};
}
}
if (empty($output)) {
return;
}
// Link.
if ($settings['link']) {
if (isset($field['entity']->uri['path'])) {
$path = $field['entity']->uri['path'];
}
else {
$uri_info = entity_uri($field['entity_type'], $field['entity']);
$path = $uri_info['path'];
}
$output = l($output, $path);
}
else {
$output = check_plain($output);
}
// Wrapper and class.
if (!empty($settings['wrapper'])) {
$wrapper = check_plain($settings['wrapper']);
$class = !empty($settings['class']) ? ' class="' . check_plain($settings['class']) . '"' : '';
$output = '<' . $wrapper . $class . '>' . $output . '</' . $wrapper . '>';
}
return $output;
}