*** hs_taxonomy.module	Tue Sep 29 17:13:46 2009
--- hs_taxonomy.module	Wed Oct 21 23:56:53 2009
***************
*** 302,307 ****
--- 302,356 ----
        $form['taxonomy']['#tree'] = TRUE;
      }
    }
+   
+ 	/*
+ 	This fix basically makes sure that content_taxonomy_form_alter() is run 
+ 	after the other changes. All this code does is hide the core taxonomy fields that are being
+      used as content_taxonomy-fields. Otherwise the node-form UI would be very confusing.	
+ 	
+ 	This could also be done by altering module weigths, but it would cause other problems.
+ 	This way some code is duplicated, but it shouldn't have any side effects.
+ 	
+ 	More info: http://drupal.org/node/601500
+ 	*/
+     if(module_exists('hs_content_taxonomy')){
+       if (isset($form['type']['#value']) && $form['type']['#value'] .'_node_form' == $form_id && isset($form['taxonomy'])) {
+ 		if (!is_array($form['taxonomy'])) {
+ 		  // empty taxonomy arrays can cause errors on preview
+ 		  if ($form_state['post']['op'] == t('Preview')) {
+ 			$form['taxonomy'] = array('#tree' => TRUE);
+ 			$form['taxonomy']['key'] = array('#type' => 'value', '#value' => '');
+ 			return;
+ 		  }
+ 		}
+ 		$_content_taxonomy_vids = array();
+ 		$info = _content_type_info();
+ 		$content_type = $info['content types'][$form['type']['#value']];
+ 		foreach ($content_type['fields'] as $field) {
+ 		  if ($field['type'] == 'content_taxonomy' && (!in_array($field['vid'], $_content_taxonomy_vids))) {
+ 			$_content_taxonomy_vids[] = $field['vid'];
+ 		  }
+ 		}
+ 		_content_taxonomy_taxonomy_unset($form['taxonomy'], $_content_taxonomy_vids);
+ 	   
+ 		//hide empty 'Vocabularies' fieldsets
+ 		$empty_fieldset = TRUE;
+ 		if (is_array($form['taxonomy'])) {
+ 		  foreach ($form['taxonomy'] as $key => $value) {
+ 			if (is_array($value) && !empty($value)) {
+ 			  $empty_fieldset = FALSE;
+ 			  break;
+ 			}
+ 		  }
+ 		}
+ 		if ($empty_fieldset) {
+ 		  // creating an empty taxonomy array is causing errors on preview in the taxonomy module
+ 		  // so we create an empty value field as placeholder, which is going to prevent the errors
+ 		  $form['taxonomy'] = array('#tree' => TRUE);
+ 		  $form['taxonomy']['key'] = array('#type' => 'value', '#value' => '');
+ 		}
+ 	 }
+   }   
  }
  
  
