You are here

Drupal专业开发指南 第14章 为术语提供自定义路径

g089h515r806 的头像
Submitted by g089h515r806 on 星期五, 2009-08-21 15:48

老葛的Drupal培训班 Think in Drupal

如果你的模块负责维护一个词汇表,你可能想为该模块控制的术语提供自定义路径,来代替由taxonomy.module提供的默认路径taxonomy/term/[term id]。当为一个术语生成一个链接时,调用taxonomy.module中的taxonomy_term_path()函数(你应该调用这个函数,而不是自己为分类术语创建链接;不要假定分类模块维护了该分类)。注意,在下面的代码中,它是如何检查哪个模块拥有该词汇表的:
 
/**
 * For vocabularies not maintained by taxonomy.module, give the maintaining
 * module a chance to provide a path for terms in that vocabulary.
 *
 * @param $term
 * A term object.
 * @return
 * An internal Drupal path.
 */
function taxonomy_term_path($term) {
    $vocabulary = taxonomy_get_vocabulary($term->vid);
    if ($vocabulary->module != 'taxonomy' &&
        $path = module_invoke($vocabulary->module, 'term_path', $term)) {
            return $path;
    }
    return 'taxonomy/term/'. $term->tid;
}
 
    例如,image_gallery.module将路径重定向为了image/tid/[term id]:
 
function image_gallery_term_path($term) {
    return 'image/tid/'. $term->tid;
}

Drupal版本: