function _taxonomy_entity_index_get_terms_array in Taxonomy Entity Index 8
Same name and namespace in other branches
- 7 taxonomy_entity_index.tokens.inc \_taxonomy_entity_index_get_terms_array()
Helper function to get terms.
1 call to _taxonomy_entity_index_get_terms_array()
- taxonomy_entity_index_tokens in includes/
taxonomy_entity_index.tokens.inc - Implements hook_tokens().
File
- includes/
taxonomy_entity_index.tokens.inc, line 85 - Token integration for the taxonomy_entity_index module.
Code
function _taxonomy_entity_index_get_terms_array($entity_type, $entity) {
list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity);
// @todo How to properly 'order' these by field/delta?
$tids = \Drupal::database()
->query("SELECT tid FROM {taxonomy_entity_index} WHERE entity_type = :type AND entity_id = :id AND revision_id = :vid ORDER BY delta", [
':type' => $entity_type,
':id' => $entity_id,
':vid' => isset($revision_id) ? $revision_id : $entity_id,
])
->fetchCol();
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadMultiple($tids);
foreach ($terms as $tid => $term) {
$terms[$tid] = $term->name;
}
return $terms;
}