You are here

function relation_rules_get_related_entities in Relation 7

Same name and namespace in other branches
  1. 8.2 relation.rules.inc \relation_rules_get_related_entities()
  2. 8 relation.rules.inc \relation_rules_get_related_entities()

Related entities getter callback.

1 string reference to 'relation_rules_get_related_entities'
relation_entity_property_info_alter in ./relation.module
Implements hook_entity_property_info_alter().

File

./relation.rules.inc, line 173
Implements the Rules module API for Relation.

Code

function relation_rules_get_related_entities($entity, array $options, $name, $type, $info) {
  $source_entity = entity_metadata_wrapper($type, $entity);
  $source_entity_type = $source_entity
    ->type();
  $source_entity_id = $source_entity
    ->getIdentifier();
  $results = relation_query($source_entity_type, $source_entity_id)
    ->entityCondition('bundle', $info['relation_type'])
    ->execute();
  $rids = array_keys($results);
  $entities_ids = array();
  if (!$rids) {
    return $entities_ids;
  }
  foreach (relation_load_multiple($rids) as $relation) {
    foreach ($relation->endpoints[LANGUAGE_NONE] as $endpoint) {
      if ($endpoint['entity_type'] == $info['target_type']) {
        $entities_ids[] = $endpoint['entity_id'];
      }
    }
  }
  return $entities_ids;
}