--- hs_content_taxonomy.info	Wed Dec 03 07:06:44 2008
+++ hs_content_taxonomy.info	Wed Jan 14 15:05:17 2009
@@ -4 +4,3 @@
-dependencies = hierarchical_select content_taxonomy hs_taxonomy
+dependencies[] = hierarchical_select
+dependencies[] = content_taxonomy
+dependencies[] = hs_taxonomy
@@ -6,7 +8 @@
-
-; Information added by drupal.org packaging script on 2008-12-03
-version = "6.x-3.x-dev"
-core = "6.x"
-project = "hierarchical_select"
-datestamp = "1228306004"
-
+core = 6.x
--- hs_content_taxonomy.module	Sun Nov 30 21:21:18 2008
+++ hs_content_taxonomy.module	Wed Jan 14 15:05:17 2009
@@ -20,3 +19,0 @@
-define('HS_CONTENT_TAXONOMY_SEPARATOR', '<span class="hierarchical-select-item-separator">›</span>');
-
-
@@ -29,2 +26,11 @@
-function hs_content_taxonomy_menu($may_cache) {
-  $items = array();
+function hs_content_taxonomy_menu() {
+		$items['admin/content/node-type/%/fields/%/hs_config'] = array(
+				'title'							=> t('HS config'),
+				'access arguments' 	=> array('administer site configuration'),
+				'page callback' 		=> 'drupal_get_form',
+				'page arguments' 		=> array('hs_content_taxonomy_config_form', 3, 5),
+				'type' 							=> MENU_NORMAL_ITEM,
+				'file' 							=> 'hs_content_taxonomy.admin.inc',
+		);
+	return $items;
+}
@@ -32,4 +38 @@
-  if (!$may_cache) {
-    $context = _hs_content_taxonomy_parse_context_from_url();
-    if (is_array($context)) {
-      list($content_type_name, $field_name) = $context;
+function hs_content_taxonomy_form_submit(&$form, &$form_state){
@@ -37 +40,2 @@
-      $content_type = content_types($content_type_name);
+	foreach ($form['#field_info'] as $field_name=>&$field_info){
+    if ($field_info['widget']['type'] == 'content_taxonomy_hs'){
@@ -39,7 +43,15 @@
-      $items[] = array(
-        'path' => 'admin/content/types/'. $content_type['url_str'] .'/fields/'. $field_name .'/hs_config',
-        'title' => t('Hierarchical Select configuration for !field', array('!field' => $content_type['fields'][$field_name]['widget']['label'])),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('hs_content_taxonomy_config_form', $content_type['type'], $field_name),
-        'access' => user_access('administer content types'),
-        'type' => MENU_CALLBACK,
+			/*
+			 @todo: Loze: the majority of my edits are here in this function.
+			 there is probably a more elegant way of doing this, 
+			 but the array of tids we not being set to the content_taxonomy module it the format it expected. 
+			
+			// i think this is right, now.
+			
+			 [field_name]
+				 [0] = array('value' => $tid)
+				 [1] = array('value' => $tid)
+				 [2] = array('value' => $tid)
+				 [tids] = array(
+								 [0] = array('value' => $tid)
+								 [1] = array('value' => $tid)
+								 [2] = array('value' => $tid)
@@ -46,0 +59,17 @@
+			 
+			
+			*/
+			
+			if(is_array($form_state['values'][$field_name]['tids'])){
+				$values = array();
+				foreach($form_state['values'][$field_name]['tids'] as $tid){
+					$values[] = array('value' => $tid);
+					array_unshift($form_state['values'][$field_name], array('value' => $tid));
+				}
+				$form_state['values'][$field_name]['tids'] = $values;
+				
+			} else {
+				$values[] = array('value' => $form_state['values'][$field_name]['tids']);
+				array_unshift($form_state['values'][$field_name],array('value' => $form_state['values'][$field_name]['tids']));
+				$form_state['values'][$field_name]['tids'] = $values;
+			}
@@ -49,2 +77,0 @@
-  return $items;
-}
@@ -51,0 +79 @@
+}
@@ -56,21 +84,7 @@
-function hs_content_taxonomy_form_alter($form_id, &$form) {
-  if ($form_id == '_content_admin_field') {
-    if ($form['widget']['widget_type']['#default_value'] == 'content_taxonomy_hs') {
-      // Hide the "multiple values" setting, so the user can't change it.
-      $form['field']['multiple']['#type'] = 'hidden';
-
-      // Add a fake checkbox form item to indicate the current state of this
-      // setting. Because this checkbox is disabled, it won't be submitted,
-      // and that's why we have to add a fake form item.
-      $split = array_search('multiple', array_keys($form['field'])) + 1;
-      $first_part = array_slice($form['field'], 0, $split);
-      $second_part = array_slice($form['field'], $split);
-      $form['field'] = $first_part;
-      $form['field']['fake_multiple'] = $form['field']['multiple'];
-      $form['field']['fake_multiple']['#type'] = 'checkbox';
-      $form['field']['fake_multiple']['#attributes'] = array('disabled' => 'disabled');
-      $form['field']['fake_multiple']['#description'] = t(
-        'This setting is now managed by the Hierarchical Select widget
-        configuration!'
-      );
-      $form['field'] += $second_part;
+function hs_content_taxonomy_form_alter(&$form, &$form_state, $form_id) {
+	if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id){
+		foreach ($form['#field_info'] as $field_name=>&$field_info){
+			if ($field_info['widget']['type'] == 'content_taxonomy_hs'){
+			  $form['#submit'][] = 'hs_content_taxonomy_form_submit';
+			  break;
+			}
@@ -85,78 +98,0 @@
-/**
- * Form definition; configuration form for Hierarchical Select as the widget
- * for a content_taxonomy field.
- *
- * @param $content_type_name
- *   Name of a content type. Provides necessary context.
- * @param $field_name
- *   Name of a field. Provides necessary context.
- */
-function hs_content_taxonomy_config_form($content_type_name, $field_name) {
-  require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
-
-  drupal_add_css(drupal_get_path('module', 'hs_content_taxonomy') .'/hs_content_taxonomy.css');
-
-  $content_type = content_types($content_type_name);
-  $field = $content_type['fields'][$field_name];
-
-  // Extract the necessary context from the $field array.
-  $vid = $field['vid'];
-  $tid = $field['tid'];
-  $depth = (empty($field['depth'])) ? 0 : $field['depth'];
-
-  // Add the Hierarchical Select config form.
-  $module = 'hs_content_taxonomy';
-  $params = array(
-    'vid'   => $vid,
-    'tid'   => $tid,
-    'depth' => $depth,
-  );
-  $config_id = "content-taxonomy-$field_name";
-  $vocabulary = taxonomy_get_vocabulary($vid);
-  $defaults = array(
-    // Enable the save_lineage setting by default if the multiple parents
-    // vocabulary option is enabled.
-    'save_lineage' => (int) ($vocabulary->hierarchy == 2),
-    'editability' => array(
-      'max_levels' => min($depth, _hs_taxonomy_hierarchical_select_get_depth($vid)),
-    ),
-  );
-  // If this config is being created (not edited), then enable the dropbox if
-  // this is a "multiple values" field. This allows for an intuitive
-  // transition to a Hierarchical Select widget.
-  if (variable_get('hs_config_'. $config_id, FALSE) === FALSE) {
-    $defaults['dropbox']['status'] = $field['multiple'];
-  }
-  $strings = array(
-    'hierarchy'   => t('vocabulary'),
-    'hierarchies' => t('vocabularies'),
-    'item'        => t('term'),
-    'items'       => t('terms'),
-    'item_type'   => t('term type'),
-    'entity'      => t('node'),
-    'entities'    => t('nodes'),
-  );
-  $max_hierarchy_depth = min(($depth == 0) ? 9 : $depth, _hs_taxonomy_hierarchical_select_get_depth($vid));
-  $preview_is_required = $field['required'];
-  $form['hierarchical_select_config'] = hierarchical_select_common_config_form($module, $params, $config_id, $defaults, $strings, $max_hierarchy_depth, $preview_is_required);
-
-  $form['link'] = array(
-    '#value' => l('Back to the field configuration', 'admin/content/types/'. $content_type['url_str'] .'/fields/'. $field_name),
-    '#prefix' => '<div class="cck-hierarchical-select-back-link">',
-    '#suffix' => '</div>',
-    '#weight' => -5,
-  );
-
-  $form['save'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-  );
-
-  // Add the the submit handler for the Hierarchical Select config form.
-  $parents = array('hierarchical_select_config');
-  $form['#submit']['hierarchical_select_common_config_form_submit'] = array($parents);
-
-  $form['#submit']['hs_content_taxonomy_common_config_form_submit'] = array($content_type_name, $field_name);
-
-  return $form;
-}
@@ -167 +103 @@
-function hs_content_taxonomy_common_config_form_submit($form_id, $form_state['values'], $content_type_name, $field_name) {
+function hs_content_taxonomy_common_config_form_submit( &$form, &$form_state) {
@@ -171,2 +107,2 @@
-  $content_type = content_types($content_type_name);
-  $field = $content_type['fields'][$field_name];
+	$content_type = content_types($form['#content_type_name']);
+	$field = $content_type['fields'][$form['#field_name']];
@@ -188 +124 @@
-    'field_name'  => $field_name,
+    'field_name'  => $form['#field_name'],
@@ -190,2 +126,2 @@
-    'module'      => 'content_taxonomy, hs_content_taxonomy',
-    'form_id'     => '_content_admin_field',
+    'module'      => 'content_taxonomy, hs_content_taxonomy, content',
+    'form_id'     => 'content_field_edit_form',
@@ -194 +130,2 @@
-  drupal_execute('_content_admin_field', $form_state['values'], $field['type_name'], $field_name);
+	require_once(drupal_get_path('module', 'content') .'/includes/content.admin.inc');
+	drupal_execute('content_field_edit_form', $form_state['values'], $field['type_name'], $form['#field_name']);
@@ -202 +139 @@
- * Implementation of hook_widget_info().
+ * Implementation of hook_field_info().
@@ -208,0 +146,4 @@
+      'multiple values' => CONTENT_HANDLE_MODULE,
+      'callbacks' => array(
+        'default value' => CONTENT_CALLBACK_NONE,
+      ),
@@ -212,0 +154 @@
+
@@ -220 +161,0 @@
-
@@ -223 +163,0 @@
-      $content_type = content_types($content_type_name);
@@ -225 +165 @@
-      $url = 'admin/content/types/'. $content_type['url_str'] .'/fields/'. $field_name .'/hs_config';
+			$url = 'admin/content/node-type/'. $content_type_name .'/fields/'. $field_name .'/hs_config';
@@ -230,3 +170 @@
-        settings.</a>",
-        array('!url' => url($url))
-      );
+		        settings.</a>",array('!url' => url($url)));
@@ -265,2 +203 @@
-function hs_content_taxonomy_widget($op, &$node, $field, &$node_field) {
-  if ($field['widget']['type'] == 'content_taxonomy_hs') {
+function hs_content_taxonomy_widget(&$form, &$form_state, $field, $items, $delta = 0) {
@@ -271,3 +207,0 @@
-
-    switch ($op) {
-      case 'form':
@@ -274,0 +209,5 @@
+	$node = &$form['#node'];
+	//dsm($node);
+	foreach($items as $item){
+		$selected_items[] = $item['value'];
+	}
@@ -275,0 +215 @@
+	$node_field = &$node->$field_name;
@@ -276,0 +217,2 @@
+			$form[$field_name]['#weight'] = $field['widget']['weight'];
+
@@ -291,56 +233 @@
-          // The default value comes from $node_field (thus from the CCK
-          // storage), unless it's empty, then we check if $node->taxonomy
-          // (thus 'normal' Taxonomy storage) contains a value, and use that
-          // instead, unless that's empty too.
-          // The latter will only work reliably if only one content_taxonomy
-          // field is being used, because when you have multiple
-          // content_taxonomy fields that use the same vocabulary, there's no
-          // way to distinguish.
-          '#default_value' => ((is_array($node_field[$tid])) ? array_keys($node_field[$tid]) : ((is_array($node->taxonomy)) ? array_keys($node->taxonomy) : array())),
-        );
-        hierarchical_select_common_config_apply($form[$field_name]['tids'], "content-taxonomy-$field_name");
-        return $form;
-
-      case 'process form values':
-        // TRICKY: this piece of utterly ugly, crappy and dysfunctional code
-        // is here thanks to the ugly internal works of the content_taxonomy
-        // module that don't make any sense at all. It's necessary to support
-        // the 'both' (and 'cck') "save option" of content_taxonomy.
-        if (isset($field['save']) && $field['save'] != 'tag') {
-          if ($field['multiple'] && is_array($node_field['tids'])) {
-            foreach ($node_field['tids'] as $key => $tid) {
-              if ($tid != 0) {
-                $keys[$tid] = $tid;
-              }
-            }
-          }
-          else {
-            $keys[$node_field['tids']] = $node_field['tids'];
-          }
-          $node_field = content_transpose_array_rows_cols(array('value' => $keys));
-        }
-        else {
-          if (!$field['multiple']) {
-            $value = $node_field['tids'];
-            $node_field['tids'] = array();
-            $node_field['tids'][0] = $value;
-          }
-        }
-        break;
-    }
-  }
-}
-
-/**
- * Implementation of hook_field_formatter_info().
- */
-function hs_content_taxonomy_field_formatter_info() {
-  return array(
-    'hierarchical_text' => array(
-      'label' => 'As hierarchical text',
-      'field types' => array('content_taxonomy'),
-    ),
-    'hierarchical_links' => array(
-      'label' => 'As hierarchical links',
-      'field types' => array('content_taxonomy'),
-    ),
+				'#default_value' => !empty($selected_items) ? array_values($selected_items) : array(),
@@ -348 +234,0 @@
-}
@@ -350,5 +235,0 @@
-/**
- * Implemenation of hook_field_formatter().
- */
-function hs_content_taxonomy_field_formatter($field, $item, $formatter, $node) {
-  $output = '';
@@ -356,3 +236,0 @@
-  if (!is_array($item)) {
-    return $output;
-  }
@@ -360,5 +238,2 @@
-  // Extract required field information.
-  $field_name = $field['field_name'];
-  $vid        = $field['vid'];
-  $tid        = $field['tid'];
-  $depth      = (empty($field['depth'])) ? 0 : $field['depth'];
+			unset($form[$field_name]['#options']); // Unset to prevent passing around of possibly huge HTML.
+			unset($form[$field_name]['#theme']);   // Unset to prevent theme_taxonomy_term_select() from running.
@@ -366,41 +241,2 @@
-  // Get the config for this field.
-  require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
-  $config_id = "content-taxonomy-$field_name";
-  $config = hierarchical_select_common_config_get($config_id);
-  $config += array(
-    'module' => 'hs_content_taxonomy',
-    'params' => array(
-      'vid'   => $vid,
-      'tid'   => $tid,
-      'depth' => $depth,
-    ),
-  );
-
-  // Generate a dropbox out of the selection. This will automatically
-  // calculate all lineages for us.
-  $selection = array_keys($item);
-  $dropbox = _hierarchical_select_dropbox_generate($config, $selection);
-
-  // Actual formatting.
-  $separator = HS_CONTENT_TAXONOMY_SEPARATOR;
-  foreach ($dropbox->lineages as $id => $lineage) {
-    if ($id > 0) {
-      $output .= '<br />';
-    }
-
-    $items = array();
-    foreach ($lineage as $level => $item) {
-      // Depending on which formatter is active, create links or use labels.
-      if ($formatter == 'hierarchical_links') {
-        $term = taxonomy_get_term($item['value']);
-        $items[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => $term->description));
-      }
-      else {
-        $items[] = $item['label'];
-      }
-    }
-    $output .= implode($separator, $items);
-  }
-
-  // Add the CSS.
-  drupal_add_css(drupal_get_path('module', 'hierarchical_select') .'/hierarchical_select.css');
+			hierarchical_select_common_config_apply($form[$field_name]['tids'], "content-taxonomy-$field_name");
+			return $form;
@@ -408 +243,0 @@
-  return $output;
@@ -431 +266,2 @@
-  $terms = _hs_taxonomy_hierarchical_select_get_tree($params['vid'], $params['tid'], -1, 1);
+	$tid = $params['tid']?$params['tid']:0;
+	$terms = _hs_taxonomy_hierarchical_select_get_tree($params['vid'], $tid, -1, 1);
@@ -440 +275,0 @@
-
@@ -547 +382 @@
-            $vocabulary = taxonomy_get_vocabulary($field['vid']);
+						$vocabulary = taxonomy_vocabulary_load($field['vid']);
@@ -558 +393 @@
-              'edit link'      => "admin/content/types/$content_type_name/fields/$field_name/hs_config",
+              'edit link'      => "admin/content/node-type/$content_type_name/fields/$field_name/hs_config",
@@ -581 +416 @@
-  if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types') {
+	if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'node-type') {
@@ -583 +417,0 @@
-    $type = node_get_types('types', $content_type['type']);
