From bf57e67f9e6a9da4796c40641376733f25ccdc2f Mon Sep 17 00:00:00 2001
From: Trevor Simonton <trevor@westernascent.com>
Date: Wed, 14 Nov 2012 21:03:09 -0700
Subject: [PATCH] Issue #1759374 by tmsimont: Altered menu callback and other functions to work with variable entity type instead of just nodes

---
 text_noderef.module |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/text_noderef.module b/text_noderef.module
index ef42d10..86c48b8 100644
--- a/text_noderef.module
+++ b/text_noderef.module
@@ -9,12 +9,12 @@
  */
 function text_noderef_menu() {
   $items = array();
-  $items['text_noderef/%/%'] = array(
+  $items['text_noderef/%/%/%'] = array(
     'title' => 'Text or Nodereference',
     'page callback' => 'text_noderef_json',
-    'page arguments' => array(1, 2),
+    'page arguments' => array(1, 2, 3),
     'access callback' => 'text_noderef_access',
-    'access arguments' => array(1, 2),
+    'access arguments' => array(1, 2, 3),
     'type' => MENU_CALLBACK,
   );
   return $items;
@@ -28,8 +28,8 @@ function text_noderef_menu() {
  * @param $field_name
  *   Field name.
  */
-function text_noderef_access($bundle_name, $field_name) {
-  return user_access('access content') && ($field = field_info_instance('node', $field_name, $bundle_name)) && field_access('view', $field, 'node') && field_access('edit', $field, 'node');
+function text_noderef_access($bundle_name, $field_name, $entity_type) {
+  return user_access('access content') && ($field = field_info_instance($entity_type, $field_name, $bundle_name)) && field_access('view', $field, $entity_type) && field_access('edit', $field, $entity_type);
 }
 
 /**
@@ -81,8 +81,8 @@ function _text_noderef_check_result($string, $field, $result) {
  * @param $string
  *   The string used as needle.
  */
-function text_noderef_json($bundle_name, $field_name, $string = '') {
-  $field = field_info_instance('node', $field_name, $bundle_name);
+function text_noderef_json($bundle_name, $field_name, $entity_type, $string = '') {
+  $field = field_info_instance($entity_type, $field_name, $bundle_name);
   $matches = array();
   // Do not act upon empty search string nor on unrelated fields.
   if (($field['widget']['type'] == 'text_noderef_textfield') && ($string != '')) {
@@ -158,7 +158,7 @@ function text_noderef_field_widget_form(&$form, &$form_state, $field, $instance,
     // autocomplete stuff.
     $instance['widget']['type'] = 'text_textfield';
     $element = text_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
-    $element['value']['#autocomplete_path'] = 'text_noderef/' . $element['#bundle'] . '/' . $element['#field_name'];
+    $element['value']['#autocomplete_path'] = 'text_noderef/' . $element['#bundle'] . '/' . $element['#field_name'] . '/' . $element['#entity_type'];
   }
   return $element;
 }
-- 
1.7.4.msysgit.0

