class DynamicEntityReference in Entity Usage 8.4
Tracks usage of entities related in dynamic_entity_reference fields.
Plugin annotation
@EntityTrack(
id = "dynamic_entity_reference",
label = @Translation("Dynamic Entity Reference"),
description = @Translation("Tracks relationships created with 'Dynamic Entity Reference' fields."),
field_types = {"dynamic_entity_reference"},
)
Hierarchy
- class \Drupal\entity_usage\EntityUsageBase extends \Drupal\entity_track\EntityTrackBase
- class \Drupal\entity_usage\Plugin\EntityTrack\Track\DynamicEntityReference
Expanded class hierarchy of DynamicEntityReference
File
- src/
Plugin/ EntityTrack/ Track/ DynamicEntityReference.php, line 18
Namespace
Drupal\entity_usage\Plugin\EntityTrack\TrackView source
class DynamicEntityReference extends EntityUsageBase {
/**
* {@inheritdoc}
*/
public function getTargetEntities(FieldItemInterface $item) {
/** @var \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem$item */
$item_value = $item
->getValue();
if (empty($item_value['target_id']) || empty($item_value['target_type'])) {
return [];
}
// Only return a valid result if the target entity exists.
if (!$this->entityTypeManager
->getStorage($item_value['target_type'])
->load($item_value['target_id'])) {
return [];
}
return [
$item_value['target_type'] . '|' . $item_value['target_id'],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DynamicEntityReference:: |
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 |