We use casetracker and pathauto at our Drupal 5 site. We're constantly struggling with figuring out which node number go with which case numbers, so I tweaked casetracker to provide two node related tokens:
[casetracker-project]
[casetracker-case]
so that we can generate paths of the form:
casetracker/[casetracker-project]/[casetracker=case]
And go directly from project/case number to the actual case in the database.
Here's the code I added to the Drupal 5 version of casetracker:
/**
* Provide token values for better pathauto alias generation.
*
* hook_token_list lets pathauto know about the availability of the casetracker
* specific node tokens.
*
* hook_token_values sets the token values.
*/
function casetracker_token_list($type) {
$tokens = array() ;
if ($type == 'node' || $type == 'all') {
$tokens['node']['casetracker-case'] = t('The ticket case number') ;
$tokens['node']['casetracker-project'] = t('The project number') ;
}
return $tokens ;
}
function casetracker_token_values($type, $object = NULL, $options = array()) {
$tokens = array() ;
if ($type == 'node') {
if (in_array($object->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE) ||
in_array($object->type, _casetracker_getCaseTypes(), TRUE)) {
$case = db_result(db_query('SELECT case_number from {casetracker_case} WHERE nid = %d', $object->nid)) ;
$project = db_result(db_query('SELECT project_number from {casetracker_project} WHERE nid = %d', $object->nid)) ;
$tokens['casetracker-case'] = $case ;
$tokens['casetracker-project'] = $project ;
foreach ($tokens as $k => $v) {
if ($v === FALSE) {
$tokens[$k] = "0" ;
}
}
}
}
return $tokens ;
}
I hope this gets added as it's made managing the cases a lot easier.
Best,
Dick Munroe
Comment | File | Size | Author |
---|---|---|---|
#3 | casetracker_tokens_1006066_3.patch | 1.26 KB | WorldFallz |
Comments
Comment #1
munroe_richard CreditAttribution: munroe_richard commentedThe code wasn't quite right. I was up at 4 am when I put it together. Here's the right code:
/**
* Provide token values for better pathauto alias generation.
*
* hook_token_list lets pathauto know about the availability of the casetracker
* specific node tokens.
*
* hook_token_values sets the token values.
*/
function casetracker_token_list($type) {
$tokens = array() ;
if ($type == 'node' || $type == 'all') {
$tokens['node']['casetracker-case'] = t('The ticket case number') ;
$tokens['node']['casetracker-project'] = t('The project number') ;
}
return $tokens ;
}
function casetracker_token_values($type, $object = NULL, $options = array()) {
$tokens = array() ;
if ($type == 'node') {
if (in_array($object->type, variable_get('casetracker_project_node_types', array('casetracker_basic_project')), TRUE)) {
$project = 'project' ;
$case = db_result(db_query('SELECT project_number from {casetracker_project} WHERE nid = %d', $object->nid)) ;
}
if (in_array($object->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
$case = db_fetch_object(db_query('SELECT case_number, pid from {casetracker_case} WHERE nid = %d', $object->nid)) ;
$project = $case->pid ;
$case = $case->case_number ;
$project = db_result(db_query('SELECT project_number from {casetracker_project} WHERE nid = %d', $project)) ;
if ($project === false) {
$project = 'case' ;
}
}
$tokens['casetracker-case'] = $case ;
$tokens['casetracker-project'] = $project ;
}
return $tokens ;
}
Comment #2
jay_N CreditAttribution: jay_N commentedHere's some (as of yet untested) code for 6.x.
In casetracker.token.inc, function casetracker_token_values:
In casetracker.token.inc, function casetracker_token_list:
Comment #3
WorldFallz CreditAttribution: WorldFallz commentedi just had a need to do this myself-- changes in #2 work great. attached is a patch against 6.x-dev for that.
Comment #4
WorldFallz CreditAttribution: WorldFallz commentedComment #5
imclean CreditAttribution: imclean commentedVery useful, thanks. Patch applies to Case Tracker included with the current (1.0-beta10) version of Open Atrium.
Comment #6
mbria CreditAttribution: mbria commentedReally useful.
Here there is a related issue: http://drupal.org/node/1345356
Patch tested against last stable release (6.x-1.0-beta9) and works like a charm.
Shouldn't it patch be included in next release?