Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for relation module relations. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions entityrelationships.module
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -182,6 +185,46 @@ function entityrelationship_entitygraph_entityreference_connections() {
return $field_relation;
}

/**
* Get relation connections.
*/
function entityrelationship_entitygraph_relation_connections() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return value is missing

$field_relation = array();

// Get all relation bundles.
$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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed out of the loop

$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.
*/
Expand Down