public function EntityUsageTrackBase::getReferencingFields in Entity Usage 8.3
Same name and namespace in other branches
- 8.2 src/EntityUsageTrackBase.php \Drupal\entity_usage\EntityUsageTrackBase::getReferencingFields()
Retrieve fields of the given types on an entity.
Parameters
\Drupal\Core\Entity\EntityInterface $source_entity: The source entity object.
string[] $field_types: A list of field types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of fields that could reference to other content entities.
Overrides EntityUsageTrackInterface::getReferencingFields
2 calls to EntityUsageTrackBase::getReferencingFields()
- EntityUsageTrackBase::getAllBottomLevelTargets in src/
EntityUsageTrackBase.php - Calculates all bottom-level targets for a given entity.
- EntityUsageTrackBase::isApplicable in src/
EntityUsageTrackBase.php - Detects whether this plugin should act on a particular entity.
File
- src/
EntityUsageTrackBase.php, line 193
Class
- EntityUsageTrackBase
- Base implementation for track plugins.
Namespace
Drupal\entity_usageCode
public function getReferencingFields(EntityInterface $source_entity, array $field_types) {
$source_entity_type_id = $source_entity
->getEntityTypeId();
$all_fields_on_bundle = $this->entityFieldManager
->getFieldDefinitions($source_entity_type_id, $source_entity
->bundle());
$referencing_fields_on_bundle = [];
foreach ($all_fields_on_bundle as $field_name => $field) {
if (in_array($field
->getType(), $field_types)) {
$referencing_fields_on_bundle[$field_name] = $field;
}
}
if (!$this->config
->get('track_enabled_base_fields')) {
foreach ($referencing_fields_on_bundle as $key => $referencing_field_on_bundle) {
if ($referencing_field_on_bundle
->getFieldStorageDefinition()
->isBaseField()) {
unset($referencing_fields_on_bundle[$key]);
}
}
}
return $referencing_fields_on_bundle;
}