Link.php in Entity Usage 8.4
File
src/Plugin/EntityTrack/Track/Link.php
View source
<?php
namespace Drupal\entity_usage\Plugin\EntityTrack\Track;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_usage\EntityUsageBase;
class Link extends EntityUsageBase {
public function getTargetEntities(FieldItemInterface $link) {
$url = $link
->getUrl();
if (!$url
->isRouted() || !preg_match('/^entity\\./', $url
->getRouteName())) {
return [];
}
$route_parameters = $url
->getRouteParameters();
$target_type = array_keys($route_parameters)[0];
$target_id = $route_parameters[$target_type];
try {
if (!$this->entityTypeManager
->getStorage($target_type)
->load($target_id)) {
return [];
}
} catch (\Exception $exception) {
return [];
}
return [
$target_type . '|' . $target_id,
];
}
}
Classes
Name |
Description |
Link |
Tracks usage of entities related in Link fields. |