private function Link::getTargetEntity in Entity Usage 8
Gets the target entity of a link item.
Parameters
\Drupal\link\LinkItemInterface $link: The LinkItem to get the target from.
Return value
string|null Target Type and ID glued together with a '|' or NULL if no entity linked.
3 calls to Link::getTargetEntity()
- Link::trackOnEntityCreation in src/
Plugin/ EntityUsage/ Track/ Link.php - Track usage updates on the creation of entities.
- Link::trackOnEntityDeletion in src/
Plugin/ EntityUsage/ Track/ Link.php - Track usage updates on the deletion of entities.
- Link::trackOnEntityUpdate in src/
Plugin/ EntityUsage/ Track/ Link.php - Track usage updates on the edition of entities.
File
- src/
Plugin/ EntityUsage/ Track/ Link.php, line 242
Class
- Link
- Tracks usage of entities related in entity_reference fields.
Namespace
Drupal\entity_usage\Plugin\EntityUsage\TrackCode
private function getTargetEntity(LinkItemInterface $link) {
// Check if LinkItem is linking to an entity.
$url = $link
->getUrl();
if (!$url
->isRouted() || !preg_match('/^entity\\./', $url
->getRouteName())) {
return NULL;
}
// Ge the target entity type and ID.
$route_parameters = $url
->getRouteParameters();
$target_type = array_keys($route_parameters)[0];
$target_id = $route_parameters[$target_type];
if (!$this->entityTypeManager
->getDefinition($target_type) instanceof ContentEntityTypeInterface) {
// This module only supports content entity types.
return NULL;
}
// Glue the target type and ID together for easy comparison.
return $target_type . '|' . $target_id;
}