private function ReferenceFinder::findTermReferenceFieldsForEntityType in Term reference change 8
Finds all term reference fields for a given entity type.
Parameters
string $entityType: The entity type name.
Return value
array The term reference fields keyed by their respective bundle.
1 call to ReferenceFinder::findTermReferenceFieldsForEntityType()
- ReferenceFinder::findTermReferenceFields in src/
ReferenceFinder.php - Finds all term reference fields.
File
- src/
ReferenceFinder.php, line 146
Class
- ReferenceFinder
- Finds entities referencing a term.
Namespace
Drupal\term_reference_changeCode
private function findTermReferenceFieldsForEntityType($entityType) {
$bundleNames = array_keys($this->entityTypeBundleInfo
->getBundleInfo($entityType));
$referenceFields = [];
foreach ($bundleNames as $bundleName) {
$fieldDefinitions = $this->entityFieldManager
->getFieldDefinitions($entityType, $bundleName);
foreach ($fieldDefinitions as $fieldDefinition) {
if ($fieldDefinition
->getType() !== 'entity_reference') {
continue;
}
if ($fieldDefinition
->getSetting('target_type') !== 'taxonomy_term') {
continue;
}
if ($fieldDefinition
->isComputed()) {
continue;
}
// Exclude parent fields because they cause fatal errors during the
// query. This is because they are currently a special case.
// @see https://www.drupal.org/node/2543726
if ($fieldDefinition
->getName() === 'parent') {
continue;
}
$referenceFields[$bundleName][] = $fieldDefinition
->getName();
}
}
return $referenceFields;
}