function shs_field_formatter_prepare_view in Simple hierarchical select 7
Implements hook_field_formatter_prepare_view().
File
- ./
shs.module, line 748 - Provides an additional widget for term fields to create hierarchical selects.
Code
function shs_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
$field_column = key($field['columns']);
foreach ($entities as $entity_id => $entity) {
if (empty($instances[$entity_id]['widget']['type']) || $instances[$entity_id]['widget']['type'] != 'taxonomy_shs') {
return;
}
foreach ($items[$entity_id] as $delta => $item) {
$items[$entity_id][$delta]['parents'] = array();
// Load list of parent terms.
$parents = taxonomy_get_parents_all($item[$field_column]);
// Remove current term from list.
array_shift($parents);
if (module_exists('i18n_taxonomy')) {
// Localize terms.
$parents = i18n_taxonomy_localize_terms($parents);
}
foreach (array_reverse($parents) as $parent) {
$items[$entity_id][$delta]['parents'][$parent->tid] = $parent;
}
// Load term.
$term_current = taxonomy_term_load($item[$field_column]);
if (module_exists('i18n_taxonomy')) {
// Localize current term.
$term_current = i18n_taxonomy_localize_terms($term_current);
}
$items[$entity_id][$delta]['term'] = $term_current;
}
}
}