class EntityReference in Entity Usage 8.4
Tracks usage of entities related in entity_reference fields.
Plugin annotation
@EntityTrack(
id = "entity_reference",
label = @Translation("Entity Reference"),
description = @Translation("Tracks relationships created with 'Entity Reference' fields."),
field_types = {"entity_reference", "entity_reference_revisions"},
)
Hierarchy
- class \Drupal\entity_usage\EntityUsageBase extends \Drupal\entity_track\EntityTrackBase
- class \Drupal\entity_usage\Plugin\EntityTrack\Track\EntityReference
Expanded class hierarchy of EntityReference
File
- src/
Plugin/ EntityTrack/ Track/ EntityReference.php, line 18
Namespace
Drupal\entity_usage\Plugin\EntityTrack\TrackView source
class EntityReference extends EntityUsageBase {
/**
* {@inheritdoc}
*/
public function getTargetEntities(FieldItemInterface $item) {
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item */
$item_value = $item
->getValue();
if (empty($item_value['target_id'])) {
return [];
}
$target_type = $item
->getFieldDefinition()
->getSetting('target_type');
// Only return a valid result if the target entity exists.
if (!$this->entityTypeManager
->getStorage($target_type)
->load($item_value['target_id'])) {
return [];
}
return [
$target_type . '|' . $item_value['target_id'],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityReference:: |
public | function |
Retrieve the target entity(ies) from a field item value. Overrides EntityUsageBase:: |
|
EntityUsageBase:: |
protected | property | The EntityRepository service. | |
EntityUsageBase:: |
protected | property | The usage config. | |
EntityUsageBase:: |
protected | property | The usage tracking service. | |
EntityUsageBase:: |
public static | function | 2 | |
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | Plugin constructor. | 2 |