? suggestedterms-all_scroll.patch ? suggestedterms.module.bk Index: suggestedterms.module =================================================================== RCS file: /cvs/drupal/contributions/modules/suggestedterms/suggestedterms.module,v retrieving revision 1.2.2.4 diff -u -p -r1.2.2.4 suggestedterms.module --- suggestedterms.module 20 May 2009 22:02:26 -0000 1.2.2.4 +++ suggestedterms.module 20 May 2009 22:34:03 -0000 @@ -9,6 +9,9 @@ define('SUGGESTEDTERMS_SORT_NAME', 1); define('SUGGESTEDTERMS_SORT_RECENT', 2); define('SUGGESTEDTERMS_SORT_WEIGHT', 3); +define('SUGGESTEDTERMS_DISPLAY_ALL', 1); +define('SUGGESTEDTERMS_DISPLAY_USED', 0); + /** * Implementation of hook_help(). */ @@ -62,25 +65,27 @@ function theme_suggestedterm($name) { * @return * A string containing the clickable spans for the suggestedterms module. */ -function _suggestedterms_build_suggestions($vid, $sort_order) { - // get total terms set by admin +function _suggestedterms_build_suggestions($vid, $sort_order, $show_terms) { + // use left join to display all entries, inner join to diaplay only used ones. + $query_type = ($show_terms == SUGGESTEDTERMS_DISPLAY_ALL) ? " LEFT " : " INNER "; + // get total terms set by admin. $total_terms = variable_get('suggestedterms_maximum_displayed', 5); // get sort order set by admin switch ($sort_order) { case SUGGESTEDTERMS_SORT_POPULAR: - $query = "SELECT t.name AS name, COUNT(t.name) AS total FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY total desc"; + $query = "SELECT t.name AS name, COUNT(t.name) AS total FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY total desc"; break; case SUGGESTEDTERMS_SORT_RECENT: - $query = "SELECT t.name AS name FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.tid desc"; + $query = "SELECT t.name AS name FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.tid desc"; break; case SUGGESTEDTERMS_SORT_WEIGHT: - $query = "SELECT t.name AS name, t.weight AS weight FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY weight, name"; + $query = "SELECT t.name AS name, t.weight AS weight FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY weight, name"; break; default: - $query = "SELECT t.name AS name FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.name"; + $query = "SELECT t.name AS name FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.name"; break; } $query_result = ($total_terms > 0) ? db_query_range($query, $vid, 0, $total_terms) : db_query($query, $vid); @@ -98,6 +103,12 @@ function suggestedterms_form_alter(&$for if ((isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) && isset($form['taxonomy']['tags'])) { $path = drupal_get_path('module', 'suggestedterms'); drupal_add_js($path . '/suggestedterms.js'); + $sort_order = variable_get('suggestedterms_sort_order', SUGGESTEDTERMS_SORT_NAME); + //set the scrollbar height according to the user's entry. + $scrollbar_height = variable_get('suggestedterms_scrollbar_height', '0'); + $scrollbar_style = ($scrollbar_height != '0' && $scrollbar_height != '0em') ? ' style="overflow:auto; height:'. $scrollbar_height .'; width:95%;"' : ''; + //Added this to be able to display all terms, including the ones that are not used by a node. + $show_terms = variable_get('suggestedterms_display_all', SUGGESTEDTERMS_DISPLAY_ALL); // If multiple vocabularies, loop over each. foreach ($form['taxonomy']['tags'] as $vid => $thisindex) { // If free-tagging taxonomy is true, add new links for each free-tag textfield. @@ -120,7 +131,7 @@ function suggestedterms_form_alter(&$for break; } // Build the suggested terms and set in description tag. - $form['taxonomy']['tags'][$vid]['#description'] .= "
\n". t($tag_description) . ': ' . _suggestedterms_build_suggestions($vid, $sort_order); + $form['taxonomy']['tags'][$vid]['#description'] .= "
\n\n". t($tag_description) .': '. _suggestedterms_build_suggestions($vid, $sort_order, $show_terms) ."\n"; } } } @@ -138,6 +149,14 @@ function suggestedterms_admin() { '#maxlength' => 2, '#description' => t('The maximum number of links to display in the block. Enter 0 to show all.'), ); + $form['suggestedterms_scrollbar_height'] = array( + '#type' => 'textfield', + '#title' => t('Height of window to display term list'), + '#default_value' => variable_get('suggestedterms_scrollbar_height', '4.3em'), + '#size' => 5, + '#maxlength' => 5, + '#description' => t('The height of the scrolling window that displays existing terms. Most useful when the maximum number of links is unlimited. The default 4.3em is about three lines in most fonts. Set to 0 for no scrollbar.'), + ); $form['suggestedterms_sort_order'] = array( '#type' => 'radios', '#title' => t('Link sort order'), @@ -150,6 +169,16 @@ function suggestedterms_admin() { SUGGESTEDTERMS_SORT_RECENT => t('Most recently added'), ), ); + $form['suggestedterms_display_all'] = array( + '#type' => 'radios', + '#title' => t('Which terms to display'), + '#default_value' => variable_get('suggestedterms_display_all', SUGGESTEDTERMS_DISPLAY_ALL), + '#description' => t("Whether to display all defined terms or only the ones previously used."), + '#options' => array( + SUGGESTEDTERMS_DISPLAY_USED => t('Previously-used terms'), + SUGGESTEDTERMS_DISPLAY_ALL => t('All terms'), + ), + ); return system_settings_form($form); }