You are here

function taxonomy_field_diff_view in Diff 7.3

Diff field callback for parsing term field comparative values.

File

includes/taxonomy.inc, line 28
Implements pusdeo-hook hook_field_diff_view() for the Taxonomy module.

Code

function taxonomy_field_diff_view($items, $context) {
  $settings = $context['settings'];
  $instance = $context['instance'];
  $diff_items = array();
  foreach ($items as $delta => $item) {
    if (!empty($item['tid'])) {
      if ($item['tid'] == 'autocreate') {
        $diff_items[$delta] = t('!term_name (new)', array(
          '!term_name' => $item['name'],
        ));
      }
      elseif (empty($item['term'])) {
        $diff_items[$delta] = t('Missing term reference (!tid)', array(
          '!tid' => $item['tid'],
        ));
      }
      else {
        $output = array();
        $output['name'] = $item['term']->name;
        if ($settings['show_id']) {
          $output['tid'] = t('Term ID: !tid', array(
            '!tid' => $item['term']->tid,
          ));
        }
        $diff_items[$delta] = implode('; ', $output);
      }
    }
  }
  if (!empty($settings['sort']) && !empty($diff_items)) {
    if ($settings['sort'] == DIFF_SORT_VALUE || $instance['widget']['type'] == 'taxonomy_autocomplete') {
      usort($diff_items, 'uasort_taxonomy_field_diff_terms');
    }
  }
  return $diff_items;
}