Index: relation.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/relation/relation.module,v
retrieving revision 1.2
diff -u -p -r1.2 relation.module
--- relation.module	24 Nov 2010 20:57:49 -0000	1.2
+++ relation.module	1 Dec 2010 04:39:48 -0000
@@ -17,7 +17,7 @@ function relation_entity_info() {
   $entities['relation'] = array(
     'label' => t('Relation'),
     'base table' => 'relation',
-    'fieldable' => FALSE,
+    'fieldable' => TRUE,
     'controller class' => 'RelationEntityController',
     'entity keys' => array(
       'id' => 'relation_id',
@@ -26,14 +26,38 @@ function relation_entity_info() {
     'bundle keys' => array(
       'bundle' => 'predicate',
     ),
-    'bundles' => array(
-      // Describe Drupal's built-in relationships.
-      'creator' => array(
-        'label' => t('Author'),
-      ),
-    ),
+    'bundles' => array(),
     'view modes' => array(),
   );
+  $entities['relation_type'] = array(
+    'label' => t('Relation type'),
+    'static cache' => FALSE,
+    'field cache' => FALSE,
+    'fieldable' => FALSE,
+    'controller class' => 'RelationTypeController',
+    'entity keys' => array(
+      'id' => 'field_name',
+      'label' => 'field_name',
+    ),
+    // Integrate with Entity API's administration UI.
+    'bundle of' => 'relation',
+    'admin ui' => array(
+      'path' => 'admin/structure/relation',
+    ),
+  );
+
+  foreach (relation_get_types() as $type => $info) {
+    $entities['relation']['bundles'][$type] = array(
+      'label' => $info['name'],
+      'admin' => array(
+        'path' => 'admin/structure/relation/manage/%relation_type',
+        'real path' => 'admin/structure/relation/manage/' . $type,
+        'bundle argument' => 4,
+//        'access arguments' => array('administer content types'),
+      ),
+    );
+  }
+
   return $entities;
 }
 
@@ -131,3 +155,47 @@ class RelationHandler implements Relatio
   }
 }
 
+class RelationTypeController extends DrupalDefaultEntityController {
+  function load($ids = array(), $conditions = array()) {
+    $entities = array();
+
+    $params = array('type' => 'relation');
+    $params += $conditions;
+    $fields = field_read_fields($params);
+    if ($ids) {
+      foreach ($ids as $id) {
+        if (isset($fields[$id])) {
+          $entities[$id] = (object) $fields[$id];
+        }
+        else {
+          $entities[$id] = FALSE;
+        }
+      }
+    }
+    else {
+      foreach ($fields as $field_name => $field) {
+        $entities[$field_name] = (object) $field;
+      }
+    }
+
+    return $entities;
+  }
+}
+
+function relation_get_types() {
+  $fields = field_read_fields(array('type' => 'relation'));
+  foreach ($fields as $field_name => $field) {
+    $types[$field_name] = array(
+      'name' => $field_name,
+    );
+  }
+  return $types;
+}
+
+function relation_type_load($type) {
+  $types = relation_get_types();
+  if (isset($types[$type])) {
+    return $types[$type];
+  }
+  return FALSE;
+}
