function pathauto_token_values in Pathauto 6
Same name and namespace in other branches
- 5.2 pathauto.module \pathauto_token_values()
- 6.2 pathauto.module \pathauto_token_values()
Implements hook_token_values().
File
- ./
pathauto.module, line 122 - Main file for the Pathauto module, which automatically generates aliases for content.
Code
function pathauto_token_values($type, $object = NULL, $options = array(), $label = NULL) {
$values = array();
switch ($type) {
case 'node':
// Token [bookpathalias].
if (module_exists('book')) {
$values['bookpathalias'] = '';
$values['bookpathalias-raw'] = '';
if (!empty($object->book['plid']) && ($parent = book_link_load($object->book['plid']))) {
$values['bookpathalias-raw'] = drupal_get_path_alias($parent['href']);
$values['bookpathalias'] = check_plain($values['bookpathalias-raw']);
}
}
// Tokens [termpath], [termpath-raw], and [termalias].
if (module_exists('taxonomy')) {
// Get the lowest-weighted term from the lowest-weighted vocabulary.
// This query is copied from @taxonomy_node_get_terms()
$term = db_fetch_object(db_query_range('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', $object->vid, 0, 1));
if ($term) {
$values = array_merge($values, pathauto_token_values('taxonomy', $term, $options, 'term'));
}
else {
$values['termpath'] = $values['termpath-raw'] = $values['termalias'] = '';
}
}
break;
case 'taxonomy':
// In the realm of nodes these are 'terms', in the realm of taxonomy, 'cats'.
if (!isset($label)) {
$label = 'cat';
}
$values[$label . 'path'] = '';
$values[$label . 'path-raw'] = '';
$values[$label . 'alias'] = '';
$values[$label . 'alias-raw'] = '';
// Tokens [catpath] and [catpath-raw].
if (isset($object->tid)) {
$parents = taxonomy_get_parents_all($object->tid);
$catpath = $catpath_raw = array();
foreach ($parents as $parent) {
array_unshift($catpath, check_plain($parent->name));
array_unshift($catpath_raw, $parent->name);
}
$values[$label . 'path'] = !empty($options['pathauto']) ? $catpath : implode('/', $catpath);
$values[$label . 'path-raw'] = !empty($options['pathauto']) ? $catpath_raw : implode('/', $catpath_raw);
// Token [catalias-raw] and [catalias].
$values[$label . 'alias-raw'] = drupal_get_path_alias(taxonomy_term_path($object));
$values[$label . 'alias'] = check_plain($values[$label . 'alias-raw']);
}
break;
}
return $values;
}