Created
April 28, 2010 15:38
-
-
Save evandonovan/382300 to your computer and use it in GitHub Desktop.
taxonomy_token.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $Id | |
define(MODULE_DESCRIPTION, 'Provides tokens that will contain text when a taxonomy term is present. For use with taxonomy module.'); | |
/** | |
* Implements hook_help() | |
* | |
*/ | |
function taxonomy_token_help($path, $arg) { | |
switch($path) { | |
case 'admin/help#taxonomy_token': | |
return t(MODULE_DESCRIPTION); | |
break; | |
} | |
} | |
/** | |
* Implements hook_token_list(). | |
*/ | |
function taxonomy_token_token_list($type = 'all') { | |
if ($type == 'node' || $type == 'all') { | |
// Defines node tokens, using -alias at end so pathauto won't strip the /. | |
$tokens['node']['faith-alias'] = t("Alias for paths based on whether they contain faith content or not."); | |
} | |
return $tokens; | |
} | |
/** | |
* Implements hook_token_values(). | |
*/ | |
function taxonomy_token_token_values($type, $object = NULL) { | |
$values = array(); | |
switch ($type) { | |
case 'node': | |
// Sets values for node tokens | |
$node = $object; | |
$values['faith-alias'] = taxonomy_token_get_value($node); | |
break; | |
} | |
return $values; | |
} | |
/** | |
* Gets the value of a taxonomy token, based on content type and presence of taxonomy term. | |
*/ | |
function taxonomy_token_get_value($node = NULL) { | |
if($node == NULL) { return ''; } | |
$faith_tid = 15180; | |
$nonfaith_tid = 3; | |
if((in_array($faith_tid, $node->taxonomy)) || (in_array($faith_tid, array_keys($node->taxonomy)))) { | |
$path = "sermons/"; | |
} | |
elseif(in_array($nonfaith_tid, $node->taxonomy)) { | |
$path = "resources/"; | |
} | |
else { | |
$path = ""; | |
} | |
return $path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment