You are here

function redhen_relation_endpoints in RedHen CRM 7

Set relation endpoints helper function.

Parameters

string $relation_type: Type or relation.

string $entity_to_relate_type: Related entity type.

object $entity_id: Entity ID.

object $entity: Entity.

Return value

array Relation endpoints.

1 call to redhen_relation_endpoints()
redhen_relation_connection_form_submit in modules/redhen_relation/includes/redhen_relation.forms.inc
Submit handler for redhen_relation_connection_form().

File

modules/redhen_relation/includes/redhen_relation.forms.inc, line 417
Form definition and handling for redhen relations.

Code

function redhen_relation_endpoints($relation_type, $entity_to_relate_type, $entity_id, $entity) {
  $relation_type = relation_type_load($relation_type);
  list($src_relation_entity_type) = explode(":", $relation_type->source_bundles[0]);

  // Ensure source/target order are correct.
  if ($relation_type->directional && $entity_to_relate_type == $src_relation_entity_type) {
    $endpoints = array(
      array(
        'entity_type' => $entity_to_relate_type,
        'entity_id' => $entity_id,
      ),
      array(
        'entity_type' => $entity
          ->entityType(),
        'entity_id' => $entity
          ->internalIdentifier(),
      ),
    );
  }
  else {
    $endpoints = array(
      array(
        'entity_type' => $entity
          ->entityType(),
        'entity_id' => $entity
          ->internalIdentifier(),
      ),
      array(
        'entity_type' => $entity_to_relate_type,
        'entity_id' => $entity_id,
      ),
    );
  }
  return $endpoints;
}