home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (token_taxonomy.inc)

This example Drupal source code file (token_taxonomy.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

all, array, category, check_plain, function, language, of, php, taxonomy, the, translate, type, vid, vocabulary

The token_taxonomy.inc Drupal example source code

<?php
// $Id: token_taxonomy.inc,v 1.3.4.5 2010/06/05 16:45:58 davereid Exp $

/**
 * @file
 * Implementations of token module hooks for the core taxonomy module.
 *
 * The token module requires specific hooks to be added to modules
 * so that those modules can return data about their objects to the
 * token API.  Until and unless token becomes a part of core, the
 * implementations of the token hooks for core modules are provided
 * in the token module itself.
 *
 * @ingroup token
 */

/**
 * Implementation of hook_token_values().
 */
function taxonomy_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'taxonomy':
      $category = $object;
      $vid = $category->vid;
      $vocabulary = taxonomy_vocabulary_load($vid);

      $values['tid'] = $category->tid;
      $values['cat'] = check_plain($category->name);
      $values['cat-raw'] = $category->name;
      $values['cat-description'] = filter_xss($category->description);
      $values['vid'] = $vid;
      $values['vocab'] = check_plain($vocabulary->name);
      $values['vocab-raw'] = $vocabulary->name;
      $values['vocab-description'] = filter_xss($vocabulary->description);

      break;
  }
  return $values;
}

/**
 * Implementation of hook_token_list().
 */
function taxonomy_token_list($type = 'all') {
  if ($type == 'taxonomy' || $type == 'all') {
    $tokens['taxonomy']['tid'] = t('The id number of the category.');
    $tokens['taxonomy']['cat'] = t('The name of the category.');
    $tokens['taxonomy']['cat-raw'] = t('The unfiltered name of the category.');
    $tokens['taxonomy']['cat-description'] = t('The optional description of the taxonomy term.');
    $tokens['taxonomy']['vid'] = t("The id number of the category's parent vocabulary.");
    $tokens['taxonomy']['vocab'] = t("The vocabulary that the page's first category belongs to.");
    $tokens['taxonomy']['vocab-raw'] = t("The unfiltered vocabulary that the page's first category belongs to.");
    $tokens['taxonomy']['vocab-description'] = t('The optional description of the taxonomy vocabulary.');

    return $tokens;
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal token_taxonomy.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.