You are here

function relation_get_endpoints_by_endpoint_type in Relation 7

Returns the endpoints of a specific endpoint type.

Parameters

object $relation: A relation object containing the endpoints.

string $endpoint_type: (optional) The endpoint type, either 'source' or 'target'.

Return value

array The endpoints.

3 calls to relation_get_endpoints_by_endpoint_type()
relation_get_endpoints in ./relation.module
Returns endpoint entities (or entity IDs).
relation_rules_get_specific_endpoints in ./relation.rules.inc
Entity-type specific property getter callback.
relation_tokens in ./relation.tokens.inc
Implements hook_tokens().

File

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

Code

function relation_get_endpoints_by_endpoint_type($relation, $endpoint_type = 'source') {
  if (empty($endpoint_type)) {
    return $relation->endpoints[LANGUAGE_NONE];
  }
  if (!in_array($endpoint_type, array(
    'source',
    'target',
  ))) {
    return array();
  }
  $relation_type = relation_type_load($relation->relation_type);
  $endpoint_type = $relation_type->directional ? $endpoint_type : 'source';

  // At present, relation only supports a 1-to-many directional relation. In
  // other words, a directional relation may only have one source endpoint; all
  // other endpoints are target endpoints.
  if ($endpoint_type == 'source') {
    if ($relation_type->directional) {
      $endpoints = array(
        $relation->endpoints[LANGUAGE_NONE][0],
      );
    }
    else {
      $endpoints = $relation->endpoints[LANGUAGE_NONE];
    }
  }
  else {
    $endpoints = array_slice($relation->endpoints[LANGUAGE_NONE], 1);
  }
  return $endpoints;
}