public function ConnectionService::getAllConnectionEntityTypes in RedHen CRM 8
Get all entities that are used in connections.
Return value
array An array of entity_types.
Overrides ConnectionServiceInterface::getAllConnectionEntityTypes
File
- modules/
redhen_connection/ src/ ConnectionService.php, line 195
Class
- ConnectionService
- Provides an interface for getting connections between entities.
Namespace
Drupal\redhen_connectionCode
public function getAllConnectionEntityTypes() {
// Load all connection types.
$query = $this->entityTypeManager
->getStorage('redhen_connection_type')
->getQuery();
$results = $query
->execute();
$connection_types = [];
$connection_entity_types = [];
if (!empty($results)) {
$connection_types = ConnectionType::loadMultiple($results);
}
foreach ($connection_types as $type) {
$bundle1 = $type
->getEndpointEntityTypeId(1);
$bundle2 = $type
->getEndpointEntityTypeId(2);
$connection_entity_types[$bundle1] = $bundle1;
$connection_entity_types[$bundle2] = $bundle2;
}
// Get all entity types.
$all_entity_types = $this->entityTypeManager
->getDefinitions();
// Iterate over entity types and remove if not in any connection types.
foreach ($all_entity_types as $key => $entity_type) {
if (!array_key_exists($key, $connection_entity_types)) {
unset($all_entity_types[$key]);
}
}
return $all_entity_types;
}