From 47660b6627b8a57f43001c64708d6e0a6d471366 Mon Sep 17 00:00:00 2001 From: Mikko Rantanen Date: Thu, 28 Jan 2016 17:30:24 +0200 Subject: [PATCH 1/2] Add support for relation module relations. --- entityrelationships.module | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/entityrelationships.module b/entityrelationships.module index 73ab78d..32eb74a 100644 --- a/entityrelationships.module +++ b/entityrelationships.module @@ -41,6 +41,9 @@ function entityrelationships_entitygraph($include_fields = FALSE, $single_entity $graph = array(); $entity_refs = entityrelationship_entitygraph_entityreference_connections(); + if (module_exists('relation')) { + $entity_refs = array_merge($entity_refs, entityrelationship_entitygraph_relation_connections()); + } if ($single_entity_type) { $entities = array($single_entity_type => entity_get_info($single_entity_type)); } @@ -182,6 +185,46 @@ function entityrelationship_entitygraph_entityreference_connections() { return $field_relation; } +/** + * Get relation connections. + */ +function entityrelationship_entitygraph_relation_connections() { + $field_relation = array(); + + // Get all entityreference field names + $query = db_select('relation_bundles', 'b'); + $query->fields('b'); + $rows = $query->execute(); + + // Create an associative array: + // $ar[source_type][source_bundle][field_name][target_type][target_bundle] + foreach ($rows as $row) { + // Skip wildcard entity_type for now. + if ($row->entity_type == '*') { + continue; + } + $bundles = array(); + if ($row->bundle == '*') { + if (!isset($info)) { + $info = entity_get_info(); + } + $bundles = array_keys($info[$row->entity_type]['bundles']); + } + else { + $bundles[] = $row->bundle; + } + foreach ($bundles as $bundle) { + $field_relation['relation'][$row->relation_type]['endpoints'][$row->entity_type] = array ( + 'bundle' => $bundle, + 'cardinality' => 1, + 'required' => 0, + ); + } + } + + return $field_relation; +} + /** * Get entity name by table. */ From 2996d89af6cdd4b2d5d10903e28082ebd8044307 Mon Sep 17 00:00:00 2001 From: Mikko Rantanen Date: Thu, 28 Jan 2016 17:44:57 +0200 Subject: [PATCH 2/2] Fix copy pasted comment --- entityrelationships.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entityrelationships.module b/entityrelationships.module index 32eb74a..0bb7c42 100644 --- a/entityrelationships.module +++ b/entityrelationships.module @@ -191,7 +191,7 @@ function entityrelationship_entitygraph_entityreference_connections() { function entityrelationship_entitygraph_relation_connections() { $field_relation = array(); - // Get all entityreference field names + // Get all relation bundles. $query = db_select('relation_bundles', 'b'); $query->fields('b'); $rows = $query->execute();