function radioactivity_field_formatter_view in Radioactivity 7
Same name and namespace in other branches
- 7.2 radioactivity.field.inc \radioactivity_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
radioactivity.field.inc, line 136
Code
function radioactivity_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case RADIOACTIVITY_AJAX_FORMATTER:
$entity_id = 0;
$info = entity_get_info($entity_type);
$id = $info['entity keys']['id'];
$entity_id = $entity->{$id};
if ($entity_id > 0) {
radioactivity_entities($field['id'], $entity_type, $entity_id);
}
break;
case RADIOACTIVITY_ENERGY_FORMATTER:
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#markup' => $item[RADIOACTIVITY_FIELD_ENERGY],
);
}
break;
case RADIOACTIVITY_POPULARITY_FORMATTER:
$maximum = ceil(radioactivity_get_field_maximum($field['id'], $entity_type));
foreach ($items as $delta => $item) {
$energy = $item[RADIOACTIVITY_FIELD_ENERGY];
$energy = $energy > 0 ? $energy : $field_info['settings']['cut_off'];
$element[$delta] = array(
'#markup' => round($energy / $maximum * 100),
);
}
break;
}
return $element;
}