function i18n_taxonomy_field_formatter_view in Internationalization 7
Implements hook_field_formatter_view().
File
- i18n_taxonomy/
i18n_taxonomy.module, line 199 - i18n taxonomy module
Code
function i18n_taxonomy_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$language = i18n_language_interface();
// Terms whose tid is 'autocreate' do not exist
// yet and $item['taxonomy_term'] is not set. Theme such terms as
// just their name.
switch ($display['type']) {
case 'i18n_taxonomy_term_reference_link':
foreach ($items as $delta => $item) {
if ($item['tid'] == 'autocreate') {
$element[$delta] = array(
'#markup' => check_plain($item['name']),
);
}
else {
if (isset($item['taxonomy_term'])) {
$term = $item['taxonomy_term'];
}
else {
$term = taxonomy_term_load($item['tid']);
}
$uri = entity_uri('taxonomy_term', $term);
$element[$delta] = array(
'#type' => 'link',
'#title' => i18n_taxonomy_term_name($term, $language->language),
'#href' => $uri['path'],
'#options' => $uri['options'],
);
}
}
break;
case 'i18n_taxonomy_term_reference_plain':
foreach ($items as $delta => $item) {
$name = $item['tid'] != 'autocreate' ? i18n_taxonomy_term_name($item['taxonomy_term'], $language->language) : $item['name'];
$element[$delta] = array(
'#markup' => check_plain($name),
);
}
break;
}
return $element;
}