From 701347e8c8fcb21be1b08032624ae4f208dbc915 Mon Sep 17 00:00:00 2001
From: Josh Walker <josh@marmaladesoul.com>
Date: Wed, 26 Jun 2013 13:14:59 +1000
Subject: [PATCH] patch for taxonomy

---
 custom_search.module |   35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/custom_search.module b/custom_search.module
index cb7f803..05094c1 100644
--- a/custom_search.module
+++ b/custom_search.module
@@ -115,10 +115,39 @@ function custom_search_form_alter(&$form, &$form_state, $form_id) {
         // Taxonomy
         if (module_exists('taxonomy')) {
           $vocabularies = taxonomy_get_vocabularies();
-          foreach ($vocabularies as $voc) {
-            if (!variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE)) unset($form['advanced']['category']['#options'][$voc->name]);
+          $options = array();
+
+          foreach ($vocabularies as $vid => $vocabulary) {
+            if (variable_get('custom_search_advanced_voc' . $vid . '_display', TRUE) == FALSE) {
+              continue;
+            }
+
+            $tree = taxonomy_get_tree($vid);
+            $options[$vocabulary->name] = array();
+
+            if ($tree) {
+              foreach ($tree as $term) {
+                $options_vid = $vid;
+                $options[$vocabulary->name][$term->tid] = str_repeat('--', $term->depth) . ' ' . $term->name;
+              }
+            }
+          }
+
+          if (!empty($options)) {
+            $type = variable_get('custom_search_voc' . $options_vid . '_selector');
+            $form['advanced']['term'] = array(
+              '#title'	=> t('Limit search to'),
+              '#type'		=> ($type == 'selectmultiple') ? 'select' : $type,
+              '#options'	=> reset($options),
+              '#prefix'	=> '<div class="criterion">',
+              '#suffix'	=> '</div>'
+            );
+            
+            if ($type == 'selectmultiple') {
+              $form['advanced']['term']['#size'] = 10;
+              $form['advanced']['term']['#multiple'] = TRUE;
+            }
           }
-          if (isset($form['advanced']['category']) && !count($form['advanced']['category']['#options'])) unset($form['advanced']['category']['#type']);
         }
 
         // Content types
-- 
1.7.9.6 (Apple Git-31.1)

