public function ContentHubEntityLinkFieldHandler::getReferencedEntities in Acquia Content Hub 8
Obtains a list of referenced entities a Link field points to.
When links are content links, it loads those entities.
Parameters
array $items: An array of field value items.
Return value
array An array of linked dependent entities.
1 call to ContentHubEntityLinkFieldHandler::getReferencedEntities()
- ContentHubEntityLinkFieldHandler::normalizeItems in src/
ContentHubEntityLinkFieldHandler.php - Converts Entity IDs into UUIDs.
File
- src/
ContentHubEntityLinkFieldHandler.php, line 131
Class
- ContentHubEntityLinkFieldHandler
- Content Hub Entity Link Field.
Namespace
Drupal\acquia_contenthubCode
public function getReferencedEntities(array $items) {
$referenced_entities = [];
foreach ($items as $key => $value) {
$uri = isset($value['uri']) ? $value['uri'] : NULL;
if (strpos($uri, 'entity:') !== FALSE) {
$link_entity = explode('/', str_replace('entity:', '', $uri));
if ($ref_entity = \Drupal::entityTypeManager()
->getStorage($link_entity[0])
->load($link_entity[1])) {
$referenced_entities[$key] = $ref_entity;
}
}
elseif (strpos($uri, 'internal:') !== FALSE) {
$link_path = str_replace('internal:', '', $uri);
$path = pathinfo($link_path);
switch ($path['dirname']) {
case '/node':
$nid = $path['filename'];
if (is_numeric($nid)) {
if ($ref_entity = \Drupal::entityTypeManager()
->getStorage('node')
->load($nid)) {
$referenced_entities[$key] = $ref_entity;
}
}
break;
case '/taxonomy/term':
$tid = $path['filename'];
if (is_numeric($tid)) {
if ($ref_entity = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->load($tid)) {
$referenced_entities[$key] = $ref_entity;
}
}
break;
}
}
}
return $referenced_entities;
}