public function ConnectionService::getConnectionTypes in RedHen CRM 8
Returns connection types that can be connected to 1 or 2 entities.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity 1.
\Drupal\Core\Entity\EntityInterface $entity2: Entity 2.
Return value
array Connection types that can be used between the 1 or 2 entities.
Overrides ConnectionServiceInterface::getConnectionTypes
1 call to ConnectionService::getConnectionTypes()
- ConnectionService::connectionQuery in modules/
redhen_connection/ src/ ConnectionService.php - Query for connections.
File
- modules/
redhen_connection/ src/ ConnectionService.php, line 81
Class
- ConnectionService
- Provides an interface for getting connections between entities.
Namespace
Drupal\redhen_connectionCode
public function getConnectionTypes(EntityInterface $entity, EntityInterface $entity2 = NULL) {
$query = $this->entityTypeManager
->getStorage('redhen_connection_type')
->getQuery();
$or_group = $query
->orConditionGroup();
$entity_type = $entity
->getEntityTypeId();
if (empty($entity2)) {
// Single entity provided.
$or_group
->condition('endpoints.1.entity_type', $entity_type);
$or_group
->condition('endpoints.2.entity_type', $entity_type);
}
else {
// Two entities provided.
$entity_type2 = $entity2
->getEntityTypeId();
$and_group = $query
->andConditionGroup()
->condition('endpoints.1.entity_type', $entity_type)
->condition('endpoints.2.entity_type', $entity_type2);
$and_group2 = $query
->andConditionGroup()
->condition('endpoints.2.entity_type', $entity_type)
->condition('endpoints.1.entity_type', $entity_type2);
$or_group
->condition($and_group)
->condition($and_group2);
}
$query
->condition($or_group);
$results = $query
->execute();
$connection_types = [];
if (!empty($results)) {
$connection_types = ConnectionType::loadMultiple($results);
}
return $connection_types;
}