--- term_display.module 2008-09-07 16:38:55.000000000 +0200 +++ term_display.module.new 2009-02-06 21:01:32.000000000 +0100 @@ -3,31 +3,78 @@ define('TERM_DISPLAY_DEFAULT', 'default'); define('TERM_DISPLAY_LIST', 'list'); +define('TERM_DISPLAY_PARENTS', 'parents'); +define('TERM_DISPLAY_NODELINKS', 'nodelinks'); define('TERM_DISPLAY_CUSTOM', 'custom'); +define('TERM_DISPLAY_PLAIN', 'plain'); define('TERM_DISPLAY_NONE', 'none'); +function term_display_theme() { + return array( + 'term_display_list' => array( + 'file' => 'term_display.module', + 'arguments' => array( + 'vocabulary' => NULL, + 'terms' => NULL, + ), + ), + 'term_display_parents' => array( + 'file' => 'term_display.module', + 'arguments' => array( + 'vocabulary' => NULL, + 'terms' => NULL, + ), + ), + 'term_display_nodelinks' => array( + 'file' => 'term_display.module', + 'arguments' => array( + 'vocabulary' => NULL, + 'terms' => NULL, + 'title' => NULL, + ), + ), + 'term_display_custom' => array( + 'file' => 'term_display.module', + 'arguments' => array( + 'vocabulary' => NULL, + 'terms' => NULL, + ), + ), + 'term_display_plain' => array( + 'file' => 'term_display.module', + 'arguments' => array( + 'vocabulary' => NULL, + 'terms' => NULL, + ), + ), + ); +} + /** * Implementation of hook_form_alter(). */ function term_display_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { $term_display_data = term_display_data($form['vid']['#value']); - + $form['term_display'] = array( '#type' => 'fieldset', '#title' => t('Display options'), '#collapsible' => TRUE, '#collapsed' => FALSE, - '#description' => t('Set display options on content view for terms in this vocabulary.'), + '#description' => t('Set display style for terms in this vocabulary. "parents" display style formats terms inline in parent_term->child_terms order. This setting overrides terms weight and always shows terms in this order no matter of actual weight settings. "nodelinks" retrieves nodes that are related to actual one, both are tagged with same term(s). "plain" style returns only names of terms, not links.'), '#weight' => -0.5, ); - + $options = array( TERM_DISPLAY_DEFAULT => t('default'), TERM_DISPLAY_LIST => t('list'), + TERM_DISPLAY_PARENTS => t('parents (parent-child listing)'), + TERM_DISPLAY_NODELINKS => t('nodelinks (nodes related by same term)'), TERM_DISPLAY_CUSTOM => t('custom (defaults to comma separated)'), + TERM_DISPLAY_PLAIN => t('plain (without links to terms)'), TERM_DISPLAY_NONE => t('none (hidden)'), ); - + $form['term_display']['term_display_style'] = array( '#type' => 'select', '#title' => t('Display style'), @@ -35,32 +82,13 @@ function term_display_form_taxonomy_form '#default_value' => $term_display_data['style'], '#description' => t('Select if and how you wish terms to appear on content (node) display.'), ); - + $form['term_display']['term_display_weight'] = array( '#type' => 'weight', - '#title' => t('Display style'), + '#title' => t('Display weight'), + '#delta' => 20, '#default_value' => $term_display_data['weight'], - '#description' => t('Set a weight for term display to control where terms appear in the content body. Set a low weight to move terms to the top of the content or a high one to move them to the bottom. Applies only when display style is set to "list" or "custom". This option is for advanced usage only; usually it\'s best to leave this at 0.'), - ); - -} - -function term_display_theme() { - return array( - 'term_display_list' => array( - 'file' => 'term_display.module', - 'arguments' => array( - 'vocabulary' => NULL, - 'terms' => NULL, - ), - ), - 'term_display_custom' => array( - 'file' => 'term_display.module', - 'arguments' => array( - 'vocabulary' => NULL, - 'terms' => NULL, - ), - ), + '#description' => t('Set a weight for term display to control where terms appear in the content body. Set a low weight to move terms to the top of the content or a high one to move them to the bottom. Applies to all display styles except "default" and "hidden". This option is for advanced usage only; usually it\'s best to leave this at 0.'), ); } @@ -75,10 +103,10 @@ function term_display_taxonomy($op, $typ // Fall through. case 'insert': db_query("INSERT INTO {term_display} (vid, style, weight) VALUES (%d, '%s', %d)", $object['vid'], $object['term_display_style'], $object['term_display_weight']); - break; + break; case 'delete': db_query('DELETE FROM {term_display} WHERE vid = %d', $object['vid']); - break; + break; } } } @@ -97,8 +125,7 @@ function term_display_data($vid) { } if (isset($term_display_data[$vid])) { return $term_display_data[$vid]; - } - else { + } else { return array( 'style' => TERM_DISPLAY_DEFAULT, 'weight' => 0, @@ -113,36 +140,40 @@ function term_display_nodeapi(&$node, $o switch ($op) { case 'view': if (isset($node->taxonomy)) { - $vocabularies = taxonomy_get_vocabularies($node->type); foreach ($vocabularies as $vocabulary) { $term_display_data = term_display_data($vocabulary->vid); + if ($term_display_data['style'] == TERM_DISPLAY_DEFAULT) { continue; } + $terms = array(); foreach ($node->taxonomy as $tid => $term) { if ($term->vid == $vocabulary->vid) { switch ($term_display_data['style']) { case TERM_DISPLAY_LIST: + case TERM_DISPLAY_PARENTS: + case TERM_DISPLAY_NODELINKS: case TERM_DISPLAY_CUSTOM: + case TERM_DISPLAY_PLAIN: $terms[] = $term; - // Fall through. + case TERM_DISPLAY_NONE: unset($node->taxonomy[$tid]); - break; + break; } } } if (!empty($terms)) { $node->content['term_display_'. $vocabulary->vid] = array( '#weight' => $term_display_data['weight'], - '#value' => theme('term_display_'. $term_display_data['style'], $vocabulary, $terms), + '#value' => theme('term_display_'. $term_display_data['style'], $vocabulary, $terms, $node->title), ); } } } - break; + break; } } @@ -158,7 +189,25 @@ function theme_term_display_list($vocabu $output .= "\n"; return $output; } - +/** + * Theme terms as parent->child inline list. This function overrides default weight of terms, they are always shown in this format. + */ +function theme_term_display_parents($vocabulary, $terms) { + $links = array(); + $links = _terms_display_get_parents_child ($vocabulary, $terms); + foreach($links as $link) { + $output[] = l($link->name, taxonomy_term_path($link)); + } + return '