Hi All,
Can we please add a new display type to the cvs branch so that taxonomy terms are displayed as unordered lists instead of just plain text?
I have altered the latest beta3 version using additions to hook_theme, hook_field_formatter_info and providing a new theme formatter function.
Hook_Theme:
function content_taxonomy_theme() {
return array(
'content_taxonomy_formatter_default' => array(
'arguments' => array('element' => NULL),
),
'content_taxonomy_formatter_list' => array(
'arguments' => array('element' => NULL),
),
'content_taxonomy_formatter_link' => array(
'arguments' => array('element' => NULL),
),
);
}
Hook_Field_Formatter_Info:
function content_taxonomy_field_formatter_info() {
return array(
'default' => array(
'label' => t('As Text'),
'field types' => array('content_taxonomy'),
'multiple values' => CONTENT_HANDLE_CORE,
),
'list' => array(
'label' => t('As List'),
'field types' => array('content_taxonomy'),
'multiple values' => CONTENT_HANDLE_CORE,
),
'link' => array(
'label' => t('As Link'),
'field types' => array('content_taxonomy'),
'multiple values' => CONTENT_HANDLE_CORE,
),
);
}
theme_content_taxonomy_formatter_list:
function theme_content_taxonomy_formatter_list($element) {
drupal_add_css(drupal_get_path('module', 'content_taxonomy') .'/content_taxonomy.css');
$term = taxonomy_get_term($element['#item']['value']);
return (check_plain($term->name)) ? '<ul class="content_taxonomy"><li>'.check_plain($term->name).'</li></ul>' : check_plain($term->name);
}
The way I have included the new display type requires extra css so I have included that too:
/* $Id: nodereference.css,v 1.1.2.1 2008/07/09 14:46:01 yched Exp $ */
/* CSS overrides for Views-based autocomplete results.
- #autocomplete uses "white-space:pre", which is no good with
Views' template-based rendering
- Field titles are rendered with <label> in default templates,
but we don't want the 'form' styling it gets under .form-item
*/
div.field-item ul.content_taxonomy {
clear:both;
margin-top:0px;
margin-bottom:0px;
}
Comments
Comment #1
1fast6 commentedIgnore the css header text, it was just copied from nodereference.
But this simple change gives a dramatically improved visual display for this module.
Please try it out and give feedback :)
Comment #2
mh86 commentedHi!
I would like to see this feature in Content Taxonomy. So, when the patch is ready, I'm going to commit this.
Two things:
1. I prefer having the list with once with the plain term name and once with the term link. Shouldn't be a problem to implement.
2. In case of multiple terms, the function
theme_content_taxonomy_formatter_list($element)would be called with each term. This would cause an incorrect definitions of list, because each term would have<ul><li>...</li></ul>. This would result in<ul><li>t1</li></ul><ul><li>t2</li></ul><ul><li>t3</li></ul>instead of<ul><li>t1</li><li>t2</li><li>t3</li></ul>.To solve this, don't declare this formatter as
'multiple values' => CONTENT_HANDLE_CORE,incontent_taxonomy_field_formatter_info()and use the theme('item_list',... function.Comment #3
1fast6 commentedHi Matthias,
I'm glad you like the idea.
In regards to point 1, do you mean displaying the data twice on the same row (one link and one text) or having two independent display modes i.e. a formatter for 'List as Link' and 'List as Text'. I believe this is the way other modules approach this.
Secondly, I have tried your suggestion for solving the repeated list declaration problem but I cannot get it to work properly. Can you please provide some more information on how to do it? or perhaps list the code changes yourself.
Thanks
Comment #4
JoeMcGuire commentedI've added a patch which supports comma separated list as well html ordered and unordered lists here:
http://drupal.org/node/749432#comment-2768232
It's needing review
Comment #5
xjmLooks like we can mark this duplicate of #749432: comma separated, ordered list and unordered list with JoeMcGuire's patch.