You are here

public function RelationRepositoryInterface::relationExists in Relation 8

Same name and namespace in other branches
  1. 8.2 src/RelationRepositoryInterface.php \Drupal\relation\RelationRepositoryInterface::relationExists()

Checks if a relation exists.

The following example demonstrates how to check if a relation of type 'likes' exists between two entities, user 17 and node 253.

$endpoints = array(
  array(
    'entity_type' => 'user',
    'entity_id' => 17,
  ),
  array(
    'entity_type' => 'node',
    'entity_id' => 253,
  ),
);
$relation_type = 'likes';
$results = Relation::relationExists($endpoints, $relation_type);

Parameters

array $endpoints: An array containing endpoints. Each endpoint is an array with keys 'entity_type' and 'entity_id'. The keys of each endpoint correspond to 'r_index' if $enforce_direction is TRUE.

string $relation_type: (Optional) The relation type (bundle) of the relation to be checked.

bool $enforce_direction: (Optional) Whether to enforce direction as specified in $endpoints.

Return value

array Array of Relation ID's keyed by revision ID.

1 method overrides RelationRepositoryInterface::relationExists()
RelationRepository::relationExists in src/Entity/RelationRepository.php
Checks if a relation exists.

File

src/RelationRepositoryInterface.php, line 53

Class

RelationRepositoryInterface
Relation Repository Interface.

Namespace

Drupal\relation

Code

public function relationExists(array $endpoints, $relation_type = NULL, $enforce_direction = FALSE);