From 68f80e817583abae7f7e353062e3caab3304c20c Mon Sep 17 00:00:00 2001
From: that0n3guy <peter@quadputer>
Date: Thu, 29 Sep 2011 12:54:22 -0500
Subject: [PATCH] cleaning up compatability stuff

---
 acdx_entityreference/acdx_entityreference.module |  211 +---------------------
 1 files changed, 9 insertions(+), 202 deletions(-)

diff --git a/acdx_entityreference/acdx_entityreference.module b/acdx_entityreference/acdx_entityreference.module
index fdd345b..46fac99 100644
--- a/acdx_entityreference/acdx_entityreference.module
+++ b/acdx_entityreference/acdx_entityreference.module
@@ -69,20 +69,16 @@ function acdx_entityreference_field_widget_settings_form($field, $instance) {
  */
 function acdx_entityreference_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
   $handler = entityreference_get_handler($field);
-//dsm($instance);
   if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-
-    if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-      // We let the Field API handles multiple values for us, only take
-      // care of the one matching our delta.
-      if (isset($items[$delta])) {
-        $items = array($items[$delta]);
-      }
-      else {
-        $items = array();
-      }
+    // We let the Field API handles multiple values for us, only take
+    // care of the one matching our delta.
+    if (isset($items[$delta])) {
+      $items = array($items[$delta]);
     }
-
+    else {
+      $items = array();
+    }
+    
     $entity_ids = array();
     $entity_labels = array();
 
@@ -103,14 +99,6 @@ function acdx_entityreference_field_widget_form(&$form, &$form_state, $field, $i
       }
       $entity_labels[] = $key;
     }
-//dsm('ent.mod $field');
-//dsm($field);
-//dsm('entity.mod handler');
-//
-//dsm($handler);
-//dsm('ent.mod itmes');
-//dsm($items);
-
     if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
       $path = !empty($instance['widget']['settings']['path']) ? $instance['widget']['settings']['path'] : 'entityreference/autocomplete/single';
       $element += array(
@@ -121,8 +109,6 @@ function acdx_entityreference_field_widget_form(&$form, &$form_state, $field, $i
         '#size' => $instance['widget']['settings']['size'],
         '#element_validate' => array('_entityreference_autocomplete_validate'),
       );
-//dsm($element);
-
       return array('target_id' => $element);
     }
   }
@@ -139,183 +125,4 @@ function _acdx_entityreference_autocomplete_validate($element, &$form_state, $fo
   }
   // Update the value of this element so the field can validate the product IDs.
   form_set_value($element, $value, $form_state);
-}
-
-//
-//
-//
-///**
-// * Implements hook_field_widget_form().
-// */
-//function acdx_entityreference_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
-//  $handler = entityreference_get_handler($field);
-//dsm($instance);
-//  if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe' || $instance['widget']['type'] == 'entityreference_autocomplete_deluxe_tags') {
-//
-//    if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-//      // We let the Field API handles multiple values for us, only take
-//      // care of the one matching our delta.
-//      if (isset($items[$delta])) {
-//        $items = array($items[$delta]);
-//      }
-//      else {
-//        $items = array();
-//      }
-//    }
-//
-//    $entity_ids = array();
-//    $entity_labels = array();
-//
-//    // Build an array of entities ID.
-//    foreach ($items as $item) {
-//      $entity_ids[] = $item['target_id'];
-//    }
-//
-//    // Load those entities and loop through them to extract their labels.
-//    $entities = entity_load($field['settings']['target_type'], $entity_ids);
-//
-//    foreach ($entities as $entity_id => $entity) {
-//      $label = $handler->getLabel($entity);
-//      $key = "$label ($entity_id)";
-//      // Labels containing commas or quotes must be wrapped in quotes.
-//      if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
-//        $key = '"' . str_replace('"', '""', $key) . '"';
-//      }
-//      $entity_labels[] = $key;
-//    }
-////dsm('ent.mod $field');
-////dsm($field);
-////dsm('entity.mod handler');
-////
-////dsm($handler);
-////dsm('ent.mod itmes');
-////dsm($items);
-//
-//    if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-//      $path = !empty($instance['widget']['settings']['path']) ? $instance['widget']['settings']['path'] : 'entityreference/autocomplete/single';
-//      $element += array(
-//        '#type' => 'textfield',
-//        '#maxlength' => 1024,
-//        '#default_value' => implode(', ', $entity_labels),
-//        '#autocomplete_path' => $path . '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'],
-//        '#size' => $instance['widget']['settings']['size'],
-//        '#element_validate' => array('_entityreference_autocomplete_validate'),
-//      );
-//      return array('target_id' => $element);
-//    }
-//    else {
-//      $path = !empty($instance['widget']['settings']['path']) ? $instance['widget']['settings']['path'] : 'entityreference/autocomplete/tags';
-//      $element += array(
-//        '#type' => 'textfield',
-//        '#maxlength' => 1024,
-//        '#default_value' => implode(', ', $entity_labels),
-//        '#autocomplete_path' => $path . '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'],
-//        '#size' => $instance['widget']['settings']['size'],
-//        '#element_validate' => array('_entityreference_autocomplete_tags_validate'),
-//      );
-//      return $element;
-//    }
-//  }
-
-//  dsm($instance);
-//  switch ($instance['widget']['type']) {
-//    case 'entityreference_autocomplete_deluxe':
-//      if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-//
-//        // We let the Field API handles multiple values for us, only take
-//        // care of the one matching our delta.
-//        if (isset($items[$delta])) {
-//          $items = array($items[$delta]);
-//        }
-//        else {
-//          $items = array();
-//        }
-//      }
-//
-//      $entity_ids = array();
-//      $entity_labels = array();
-//
-//      // Build an array of entities ID.
-//      foreach ($items as $item) {
-//        $entity_ids[] = $item['target_id'];
-//      }
-//
-//      // Load those entities and loop through them to extract their labels.
-//      $entities = entity_load($field['settings']['target_type'], $entity_ids);
-//
-//      $handler = entityreference_get_handler($field);
-//      foreach ($entities as $entity_id => $entity) {
-//        $label = $handler->getLabel($entity);
-//        $key = "$label ($entity_id)";
-//        // Labels containing commas or quotes must be wrapped in quotes.
-//        if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
-//          $key = '"' . str_replace('"', '""', $key) . '"';
-//        }
-//        $entity_labels[] = $key;
-//      }
-//dsm(' $field');
-//dsm($field);
-//dsm(' handler');
-//
-//dsm($handler);
-//dsm(' itmes');
-//dsm($items);
-//      if ($instance['widget']['type'] == 'entityreference_autocomplete_deluxe') {
-//        $path = !empty($instance['widget']['settings']['path']) ? $instance['widget']['settings']['path'] : 'entityreference/autocomplete/single';
-//        $element += array(
-//          '#type' => 'autocomplete_deluxe',
-//          '#maxlength' => 1024,
-//          '#size' => $instance['widget']['settings']['size'],
-//          '#default_value' => implode(', ', $entity_labels),
-//          //'#autocomplete_deluxe_path' => url($instance['widget']['settings']['autocomplete_deluxe_path'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'], array('absolute' => TRUE)),
-//          '#autocomplete_deluxe_path' => url($path . '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'], array('absolute' => TRUE)),
-//          '#element_validate' => array('_entityreference_autocomplete_validate'),
-//        );
-//        dsm($element);
-//        return array('target_id' => $element);
-//      }
-//      else {
-//        $path = !empty($instance['widget']['settings']['path']) ? $instance['widget']['settings']['path'] : 'entityreference/autocomplete/tags';
-//        $element += array(
-//          '#type' => 'textfield',
-//          '#maxlength' => 1024,
-//          '#default_value' => implode(', ', $entity_labels),
-//          '#autocomplete_path' => $path . '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'],
-//          '#size' => $instance['widget']['settings']['size'],
-//          '#element_validate' => array('_entityreference_autocomplete_tags_validate'),
-//        );
-//        return $element;
-//      }
-//
-//
-//
-//
-//      // Since the value callback doesn't work with autocomplete deluxe, we need
-//      // to set the default value here.
-//      $value = NULL;
-//      if (isset($items[$delta]['nid'])) {
-//        $element['#default_value'] = $items[$delta]['nid'];
-//        $value = entityreference_autocomplete_value($element, FALSE, $form_state);
-//      }
-//dsm($instance);
-//      $acdx = array(
-//        //'#type' => 'autocomplete_deluxe',
-//        '#default_value' => $value,
-//        //'#autocomplete_deluxe_path' => url($instance['widget']['settings']['autocomplete_deluxe_path'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'], array('absolute' => TRUE)),
-//        //'#size' => $instance['widget']['settings']['size'],
-//       // '#element_validate' => array('entityreference_autocomplete_validate'),
-//        //TODO: does not work.
-//        '#value_callback' => '_entityreference_autocomplete_validate',
-//      );
-//      // Element has already some fields and if we use += values that are
-//      // already in $element, won't be overwritten.
-//      $element = array_merge($element, $acdx);
-//      break;
-//  }
-//  return array('nid' => $element);
-//
-//
-//
-//
-//
-//}
+}
\ No newline at end of file
-- 
1.7.0.4

