DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
›
token
Fix for token
View
Fix
Fixes are not saved to the database until you submit.
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
<?php /** * Implementation of hook_token_list(). */ function token_vocab_token_list($type = 'all'){ $tokens = array(); if ($type == 'node' || $type == 'all' && module_exists('taxonomy')) { $tokens['node']['jens-test'] = t("Jen's Test Token"); $vocabs = taxonomy_get_vocabularies(NULL); foreach ($vocabs as $vid => $vocab){ $name = _token_vocab_clean_name($vocab->name); $tokens['node']['vocab-'.$name.'-term'] = t("Top term name in vocabulary: ".$name); $tokens['node']['vocab-'.$name.'-term-raw'] = t("Unfiltered name of top term in vocabulary: ".$name.". WARNING - raw user input."); $tokens['node']['vocab-'.$name.'-term-id'] = t("ID of top term in vocabulary: ".$name); } // foreach } // if type node or all and taxonomy installed return $tokens; } /** * Implementation of hook_token_values(). */ function token_vocab_token_values($type, $object = NULL){ $values = array(); $node = $object; if (($type == 'node' || $type == 'all') && module_exists('taxonomy') && !empty($node->taxonomy) && is_array($node->taxonomy)) { $values['jens-test'] = 'test'; // iterate over vocabs $vocabs = taxonomy_get_vocabularies(NULL); foreach ($vocabs as $vid => $vocab){ $name = _token_vocab_clean_name($vocab->name); // pull top term for this vocab $query = db_query("SELECT td.tid, td.name FROM {term_data} td INNER JOIN {term_node} tn ON tn.tid = td.tid WHERE td.vid = %d AND tn.nid = %d ORDER BY weight LIMIT 1", $vid, $node->nid); if ($result = db_fetch_array($query){ // set token values $values['vocab-'.$name.'-term'] = check_plain(_token_vocab_clean_name($result['name'])); $values['vocab-'.$name.'-term-raw'] = _token_vocab_clean_name($result['name']); $values['vocab-'.$name.'-term-id'] = $result['tid']; } else { // set default empty strings for all vocabs $values['vocab-'.$name.'-term'] = ''; $values['vocab-'.$name.'-term-raw'] = ''; $values['vocab-'.$name.'-term-id'] = ''; } } // foreach $data = array(); foreach ($result as $term) { $name = _token_vocab_clean_name($vocab->name); // build an array of [vocab-name] => [top-term-tid, top-term-name, top-term-name-raw] values here print_r($term);exit; $data[''] } // foreach term on node foreach ($data as $name => $term){ // set the token values $values['vocab-'.$name.'-term'] = $term['name']; $values['vocab-'.$name.'-term-raw'] = $term['name-raw']; $values['vocab-'.$name.'-term-id'] = $term['tid']; } // foreach vocab-term } // if node has vocab return $values; } function _token_vocab_clean_name($name){ $hyphen = str_replace(' ', '-', $name); $clean = strtolower($hyphen); return $clean; }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.