public static function EckEntityType::loadReferenceFieldsByType in Entity Construction Kit (ECK) 8
Load all reference fields with provided target type.
Parameters
string $target_entity_type_id: The entity type id created by ECK.
Return value
\Drupal\field\FieldConfigInterface[] Returns loaded config fields entities.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
1 call to EckEntityType::loadReferenceFieldsByType()
- EckEntityType::preDelete in src/
Entity/ EckEntityType.php - Acts on entities before they are deleted and before hooks are invoked.
File
- src/
Entity/ EckEntityType.php, line 138
Class
- EckEntityType
- Defines the ECK Entity Type config entities.
Namespace
Drupal\eck\EntityCode
public static function loadReferenceFieldsByType($target_entity_type_id) {
$entity_manager = \Drupal::entityTypeManager();
$fields_array = \Drupal::service('entity_field.manager')
->getFieldMapByFieldType('entity_reference');
$field_storage = $entity_manager
->getStorage('field_config');
/** @var \Drupal\field\FieldConfigInterface[] $fields_list */
$fields_list = $list = [];
// Get list of fields with type entity_reference.
foreach ($fields_array as $entity_type_id => $fields) {
foreach ($fields as $field_name => $info) {
foreach ($info['bundles'] as $bundle) {
if ($field = $field_storage
->load($entity_type_id . '.' . $bundle . '.' . $field_name)) {
$fields_list[] = $field;
}
}
}
}
foreach ($fields_list as $field) {
if ($field
->getSetting('target_type') == $target_entity_type_id) {
$list[] = $field;
}
}
return $list;
}