You are here

function relation_get_endpoints in Relation 7

Returns endpoint entities (or entity IDs).

Parameters

object $relation: Full relation object containing the endpoints

string $entity_type: (optional) If set, filter by entity type; else return all endpoints.

string $endpoint_type: (optional) If set, filter by endpoint type, either 'source' or 'target'; else return all endpoints.

boolean $load_entities: (optional) Whether to return entities or entity IDs.

Return value

array The endpoint entities (or entity IDs).

1 call to relation_get_endpoints()
relation_rules_get_endpoints in ./relation.rules.inc
Endpoint property getter callback.

File

./relation.module, line 791
Describes relations between entities.

Code

function relation_get_endpoints($relation, $entity_type = NULL, $endpoint_type = NULL, $load_entities = TRUE) {
  $items = array();
  $endpoints = relation_get_endpoints_by_endpoint_type($relation, $endpoint_type);
  foreach ($endpoints as $endpoint) {
    if (empty($entity_type) || $endpoint['entity_type'] == $entity_type) {
      $items[$endpoint['entity_type']][] = $endpoint['entity_id'];
    }
  }
  if ($load_entities) {
    foreach ($items as $entity_type => $ids) {
      $items[$entity_type] = entity_load($entity_type, $ids);
    }
  }
  return $items;
}