Skip to main content
added 43 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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 thethis screenshot is my theme showingshows the output of the function (will beit 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.

Much appreciated.

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) : "";
}

In the screenshot is my theme showing the output of the function (will be excluded from display), the user's name with the awards field 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.

Much appreciated.

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.

Source Link

How do I display a custom field from taxonomy term in user list in rewritten field

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) : "";
}

In the screenshot is my theme showing the output of the function (will be excluded from display), the user's name with the awards field 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.

Much appreciated.