You are here

function themekey_taxonomy_tid2name in ThemeKey 7.3

ThemeKey mapping function to set a ThemeKey property's value (destination) with the aid of another ThemeKey property (source).

src: taxonomy:tid dst: taxonomy:name

Parameters

$tids: array of taxonomy term ids or a single term id

Return value

array of taxonomy names or NULL if no value could be mapped

1 string reference to 'themekey_taxonomy_tid2name'
themekey_taxonomy_themekey_properties in modules/themekey.taxonomy.inc
Implements hook_themekey_properties().

File

modules/themekey.taxonomy.inc, line 209
Provides some taxonomy stuff as ThemeKey properties.

Code

function themekey_taxonomy_tid2name($tids) {
  $name = array();

  // Use SQL instead taxonomy API because this code runs during hook_init() stage.
  // Using taxonomy API will require to load the node using node_load() which is not allowed in this stage.
  $tids = is_array($tids) ? $tids : array(
    $tids,
  );
  foreach ($tids as $tid) {
    $name[] = db_select('taxonomy_term_data', 't')
      ->fields('t', array(
      'name',
    ))
      ->condition('tid', $tid)
      ->execute()
      ->fetchField();
  }
  return count($name) ? $name : NULL;
}