From 876a69e9f872375e0d0bf25564111d25f6e05450 Mon Sep 17 00:00:00 2001
From: alexkb <alexkb@35674.no-reply.drupal.org>
Date: Wed, 31 Jul 2013 13:57:51 +0800
Subject: [PATCH] Issue #1463552 by alexkb: adding api hook into autocomplete
 function.

---
 nodequeue.api.php |   25 +++++++++++++++++++++++++
 nodequeue.module  |   10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 nodequeue.api.php

diff --git a/nodequeue.api.php b/nodequeue.api.php
new file mode 100644
index 0000000..70ddc76
--- /dev/null
+++ b/nodequeue.api.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * @file
+ * API documentation file for Node Queue
+ */
+
+/**
+ * Allows modules to generate the autocomplete items
+ *
+ * @param $queue
+ *   The queue that owns the subqueue
+ * @param $subqueue
+ *   The subqueue
+ * @param $string
+ *   The string being matched.
+ * 
+ * @return
+ *   An keyed array $nid => $title
+ */
+function hook_nodequeue_api_autocomplete($queue, $subqueue, $string) {
+  $results = array();
+  // populate the array with title strings and keyed with node id's.
+  return $results;
+}
diff --git a/nodequeue.module b/nodequeue.module
index 312e02d..b15c18f 100644
--- a/nodequeue.module
+++ b/nodequeue.module
@@ -1776,7 +1776,15 @@ function nodequeue_api_autocomplete($queue, $subqueue, $string) {
   if (empty($string)) {
     return $matches;
   }
-
+  
+  // Let other modules determine autocomplete values if specified.
+  $matches_returned = module_invoke_all('nodequeue_api_autocomplete', $queue, $subqueue, $string);
+  $matches = array_filter($matches_returned); // remove the empty results
+  
+  if (!empty($matches)) {
+    return array_pop($matches); // return the result from the last implemented autocomplete hook.
+  }
+  
   $query = db_select('node', 'n')
     ->addTag('node_access')
     ->fields('n', array('nid', 'tnid', 'title'))
-- 
1.7.10.msysgit.1

