0

I'm trying to display a list of taxonomy custom field terms next to a user's name. Though when I use a custom function to get the custom field (abbreviation) and then use it in a rewrite it still displays the original term list.

The taxonomy field is field_awards, the custom field attached to field_awards is field_abbreviation.

This is my custom function to display the abbreviation instead of the full term:

function ppw_views_view_field__field_awards($vars) {
    $row = $vars['row'];

    $abbr = array();
    foreach ($row->field_field_awards as $record) {
        $abbr[] = $record['raw']['taxonomy_term']->field_abbreviation['und'][0]['safe_value'];

    }

    return (count($abbr) > 0) ? ", " . implode(", ", $abbr) : "";
}

screenshot

In this screenshot my theme shows the output of the function (it is excluded from display), the user's name with the awards field is rewritten into the output.

I've also tried to implement a custom field format in my theme:

function ppw_field_formatter_info() {
  return array(
    'ppw_term_reference_plain_abbreviation' => array(
      'label' => t('Plain text Abbreviation'), 
      'field types' => array('taxonomy_term_reference'),
    ),
  );
}

function ppw_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  // 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 'ppw_term_reference_plain_abbreviation':
      foreach ($items as $delta => $item) {
        $name = $item['taxonomy_term']->field_abbreviation['und'][0]['safe_value'];
        $element[$delta] = array(
          '#markup' => check_plain($name),
        );
      }
      break;
  }

  return $element;
}

How do I get the abbreviations next to the name? I've been unable to find what function to implement or what theme file to add to get this to work.

1 Answer 1

1

I solved my problem by fixing my field formatter (in its own module).

1
  • I would be an answer, if you report how you fixed the field formatter.
    – avpaderno
    Commented Sep 7, 2011 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.