Textformatter would be very useful if it also included content taxonomy fields and not just text fields.

I hope you would consider extending this functionality to content taxonomy.

Thanks.

Comments

zdean’s picture

I could use this feature as well. Is it possible to do this with the current version?

deltab’s picture

It would be great to have this for Content Taxonomy, as well as Nodereference. Is there a way I can modify/change the formatter around to get there?

jeff.k’s picture

+1

jeff.k’s picture

I have found a solution for now. I am using Custom Formatters and an entry:

Just comma



$output = '';
foreach (element_children($element) as $key) {
  $term_name = taxonomy_get_term( $element[$key]['#item']['value']); //load the value
  $output .= ($output==NULL) ? '' : ', ';
  $output .=  $term_name -> name ; 
}
return $output;

Comma with , and at then end and a "." (code was rushed so there may be a better way)


$output = '';
$choiceCount = 0;
foreach (element_children($element) as $key) {
  $choiceCount ++; // count the entries
}

$entryCount = 0;

foreach (element_children($element) as $key) {

  $term_name = taxonomy_get_term( $element[$key]['#item']['value']); //load the value

if ($choiceCount - 1 == $entryCount && $choiceCount > 1   ){
  $output .=  " and ". $term_name -> name ."."; // last entry
}
else if ($choiceCount == 2){
  $output .=  $term_name -> name; //only 2 entries, no comma
}
else if($choiceCount - 1 > $entryCount ){
  $output .=  $term_name -> name  .", "; // regular entry with comma
}
else{
  $output .=  $term_name -> name ; //single and all other entries

}
if($choiceCount == 1){
$output .= ".";//period for single entries
}
 $entryCount ++;

}
return $output;

tsaks’s picture

Hey jeff.k -

I used your first code snippet for Custom Formatter and it works great...

But how could I make the content taxonomy terms display as links?

Thanks.

mpa3b’s picture

Great thanks! 8) Works well!

becw’s picture

Status: Active » Postponed

I agree, it would be useful to apply list formatting to taxonomy term fields. However, personally I'm not interested in adding new features to the D6 version at this point. I'm gonna mark this as postponed in case someone else takes interest and submits a patch.

PLEASE BEWARE random code snippets--the above code prints UNFILTERED taxonomy term names, so if anyone untrusted can edit free-tagging fields, it will make your site vulnerable to XSS attacks. Additionally, I don't recommend storing PHP in the database, since it's hard to edit, version control, and re-use.

jwilson3’s picture

I guess this is in the D7 version, but there is also an alternative module that supports this type of comma-separated lists of taxonomy terms: field_delimiter