function hook_taxonomy_term_load

Act on taxonomy terms when loaded.

Modules implementing this hook can act on the term objects returned by taxonomy_term_load_multiple().

For performance reasons, information to be added to term objects should be loaded in a single query for all terms where possible.

Since terms are stored and retrieved from cache during a page request, avoid altering properties provided by the {taxonomy_term_data} table, since this may affect the way results are loaded from cache in subsequent calls.

Parameters

$terms: An array of term objects, indexed by tid.

Related topics

4 functions implement hook_taxonomy_term_load()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

EntityCrudHookTestHooks::taxonomyTermLoad in core/modules/system/tests/modules/entity_crud_hook_test/src/Hook/EntityCrudHookTestHooks.php
Implements hook_ENTITY_TYPE_load() for taxonomy_term entities.
entity_crud_hook_test_taxonomy_term_load in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_taxonomy_term_load().
TaxonomyTestHooks::taxonomyTermLoad in core/modules/taxonomy/tests/modules/taxonomy_test/src/Hook/TaxonomyTestHooks.php
Implements hook_ENTITY_TYPE_load() for the taxonomy term.
taxonomy_test_taxonomy_term_load in modules/simpletest/tests/taxonomy_test.module
Implements hook_taxonomy_term_load().

File

modules/taxonomy/taxonomy.api.php, line 106

Code

function hook_taxonomy_term_load($terms) {
  $result = db_select('mytable', 'm')->fields('m', array(
    'tid',
    'foo',
  ))
    ->condition('m.tid', array_keys($terms), 'IN')
    ->execute();
  foreach ($result as $record) {
    $terms[$record->tid]->foo = $record->foo;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.