From da43e5a5bfb1b341e0834c7aff0812163bfb927b Mon Sep 17 00:00:00 2001
From: Andrei Mateescu <andrei@xns.ro>
Date: Thu, 20 Oct 2011 00:05:48 +0300
Subject: [PATCH] Add tools to help find all field definitions of a specified
 field type.

---
 API.txt             |    9 ++++++---
 ctools.module       |    2 +-
 includes/fields.inc |   18 ++++++++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/API.txt b/API.txt
index b0db2e2..c924c0c 100644
--- a/API.txt
+++ b/API.txt
@@ -1,11 +1,14 @@
-Current API Version: 2.0.3
+Current API Version: 2.0.4
 
 Please note that the API version is an internal number and does not match release numbers. It is entirely possible that releases will not increase the API version number, and increasing this number too often would burden contrib module maintainers who need to keep up with API changes.
 
 This file contains a log of changes to the API.
 
-API Version 2.0.2
-  Introduce ctools_field_invoke_field() and 
+API Version 2.0.4
+  Introduce ctools_fields_get_fields_by_type().
+
+API Version 2.0.3
+  Introduce ctools_field_invoke_field() and ctools_field_invoke_field_default().
 
 API Version 2.0.2
   Introduce ctools_export_crud_load_multiple() and 'load multiple callback' to
diff --git a/ctools.module b/ctools.module
index d8b8d01..599ffb2 100644
--- a/ctools.module
+++ b/ctools.module
@@ -9,7 +9,7 @@
  * must be implemented in the module file.
  */
 
-define('CTOOLS_API_VERSION', '2.0.3');
+define('CTOOLS_API_VERSION', '2.0.4');
 
 /**
  * Test the CTools API version.
diff --git a/includes/fields.inc b/includes/fields.inc
index 8cb0bed..85c12ec 100644
--- a/includes/fields.inc
+++ b/includes/fields.inc
@@ -267,3 +267,21 @@ function ctools_field_invoke_field_default($field_name, $op, $entity_type, $enti
   return ctools_field_invoke_field($field_name, $op, $entity_type, $entity, $a, $b, $options);
 }
 
+/**
+ * Returns a list of field definitions of a specified type.
+ *
+ * @param string $field_type
+ *   A field type name; e.g. 'text' or 'date'.
+ *
+ * @return array
+ *   An array of field definitions of the specified type, keyed by field name.
+ */
+function ctools_fields_get_fields_by_type($field_type) {
+  $fields = array();
+  foreach (field_info_fields() as $field_name => $field_info) {
+    if ($field_info['type'] == $field_type) {
+      $fields[$field_name] = $field_info;
+    }
+  }
+  return $fields;
+}
-- 
1.7.6.msysgit.0

