protected function ExtraFieldTypePluginBase::getEntityFieldReferenceTypes in Entity Extra Field 2.0.x
Same name and namespace in other branches
- 8 src/ExtraFieldTypePluginBase.php \Drupal\entity_extra_field\ExtraFieldTypePluginBase::getEntityFieldReferenceTypes()
Get entity field reference types.
Parameters
string $entity_type_id: The entity type identifier.
string $entity_bundle: The entity bundle name.
Return value
array An array of reference types.
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException
2 calls to ExtraFieldTypePluginBase::getEntityFieldReferenceTypes()
- ExtraFieldTypePluginBase::getEntityTokenData in src/
ExtraFieldTypePluginBase.php - Get entity token data.
- ExtraFieldTypePluginBase::getEntityTokenTypes in src/
ExtraFieldTypePluginBase.php - Get entity token types.
File
- src/
ExtraFieldTypePluginBase.php, line 351
Class
- ExtraFieldTypePluginBase
- Define extra field type plugin base.
Namespace
Drupal\entity_extra_fieldCode
protected function getEntityFieldReferenceTypes(string $entity_type_id, string $entity_bundle) : array {
$types = [];
$fields = $this->entityFieldManager
->getFieldDefinitions($entity_type_id, $entity_bundle);
foreach ($fields as $field_name => $field) {
if ($field
->getType() !== 'entity_reference') {
continue;
}
$definition = $field
->getFieldStorageDefinition();
$target_type = $definition
->getSetting('target_type');
if (!isset($target_type) || in_array($target_type, $types, TRUE)) {
continue;
}
$type_definition = $this->entityTypeManager
->getDefinition($target_type);
if (!$type_definition instanceof ContentEntityTypeInterface) {
continue;
}
$types[$field_name] = $type_definition
->get('token_type') ?? $target_type;
}
return $types;
}