function recipe_field_formatter_view in Recipe 7.2
Implements hook_field_formatter_view().
File
- ./
recipe.module, line 740 - Contains functions for Recipe node CRUD and display.
Code
function recipe_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$elements = array();
switch ($display['type']) {
case 'recipe_duration':
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#theme' => $display['type'],
'#duration' => $item['value'],
);
}
break;
case 'recipe_ingredient_default':
$fraction_format = $display['settings']['fraction_format'];
foreach ($items as $delta => $item) {
// Sanitize the name and note.
$name = filter_xss($item['name'], array());
$note = filter_xss($item['note'], array());
if ($item['quantity'] > 0) {
// Alter the quantity based on the factor from the custom yield form
// and format it as a fraction.
$item['quantity'] *= isset($entity->recipe_factor) ? $entity->recipe_factor : 1;
$formatted_quantity = recipe_ingredient_quantity_from_decimal($item['quantity'], $fraction_format);
}
else {
$formatted_quantity = ' ';
}
// Print the unit unless it has no abbreviation. Those units do not get
// printed in any case.
$unit_display = '';
if (!empty($item['unit']['abbreviation'])) {
$title = $item['quantity'] > 1 ? $item['unit']['plural'] : $item['unit']['name'];
// Print the abbreviation if recipe_unit_display == 0.
if ($display['settings']['unit_abbreviation'] == 0) {
$unit_display = '<abbr ' . drupal_attributes(array(
'title' => $title,
)) . '>' . $item['unit']['abbreviation'] . '</abbr>';
}
else {
$unit_display = $title;
}
}
$elements[$delta] = array(
'#theme' => 'recipe_ingredient',
'#name' => $name,
'#quantity' => $formatted_quantity,
'#unit' => $unit_display,
'#note' => $note,
'#link' => $item['link'],
);
}
break;
}
return $elements;
}