function taxonomy_entity_index_get_taxonomy_field_names in Taxonomy Entity Index 8
Same name and namespace in other branches
- 7 taxonomy_entity_index.module \taxonomy_entity_index_get_taxonomy_field_names()
Return all the taxonomy entity reference field names for a given entity type.
4 calls to taxonomy_entity_index_get_taxonomy_field_names()
- TaxonomyEntityIndexFieldNamesTest::testFieldNamesUpdate in tests/
src/ Kernel/ TaxonomyEntityIndexFieldNamesTest.php - Tests caching in taxonomy_entity_index_get_taxonomy_field_names().
- taxonomy_entity_index_entity_update in ./
taxonomy_entity_index.module - Implements hook_entity_update().
- taxonomy_entity_index_reindex_entity_type in ./
taxonomy_entity_index.module - Batch callback; re-index all the terms for a given entity type.
- taxonomy_entity_index_token_info_alter in includes/
taxonomy_entity_index.tokens.inc - Implements hook_token_info_alter().
File
- ./
taxonomy_entity_index.module, line 158 - Module file for taxonomy_entity_index.
Code
function taxonomy_entity_index_get_taxonomy_field_names($entity_type_id) {
$cache_id = 'entity-taxonomy-fields_' . $entity_type_id;
$entity_ref_fields =& drupal_static($cache_id);
if (!isset($entity_ref_fields)) {
if ($cache = \Drupal::cache()
->get($cache_id)) {
$entity_ref_fields = $cache->data;
}
else {
$entity_ref_fields = [];
$entity_field_manager = \Drupal::service('entity_field.manager');
$fieldmap = $entity_field_manager
->getFieldMapByFieldType('entity_reference');
if (isset($fieldmap[$entity_type_id])) {
foreach ($fieldmap[$entity_type_id] as $field_name => $field) {
foreach ($field['bundles'] as $bundle) {
$field_definitions =& drupal_static('entity-taxonomy-field-defs' . '_' . $entity_type_id . '_' . $bundle);
if (!isset($field_definitions)) {
$field_definitions = $entity_field_manager
->getFieldDefinitions($entity_type_id, $bundle);
}
$field_definition = $field_definitions[$field_name];
$settings = $field_definition
->getSettings();
if ($settings['target_type'] === 'taxonomy_term') {
$entity_ref_fields[$bundle][] = $field_name;
}
}
}
}
\Drupal::cache()
->set($cache_id, $entity_ref_fields, Cache::PERMANENT, [
'entity_types',
'entity_field_info',
]);
}
}
return $entity_ref_fields;
}