Drupal 基于分类术语生成url别名

Drupal 基于分类术语生成url别名,drupal,drupal-7,drupal-modules,drupal-taxonomy,Drupal,Drupal 7,Drupal Modules,Drupal Taxonomy,我有一个vocab类别和四个术语。我想做的是,如果内容被标记为一个term,特别是说“term1”,那么url将被生成为word1/[node:title],而对于所有其他标记,则只需要标准的url格式 如果我想在url中使用这个术语,显然我会使用模式替换,但是如果使用了特定的标记,我想使用另一个词,我想不出一种简单的即插即用方式来实现这一点。您可能需要为Pathauto的URL别名设置中的“默认路径模式”创建自己的令牌: /** * Implementation of hook_token_

我有一个vocab类别和四个术语。我想做的是,如果内容被标记为一个term,特别是说“term1”,那么url将被生成为word1/[node:title],而对于所有其他标记,则只需要标准的url格式


如果我想在url中使用这个术语,显然我会使用模式替换,但是如果使用了特定的标记,我想使用另一个词,我想不出一种简单的即插即用方式来实现这一点。您可能需要为Pathauto的URL别名设置中的“默认路径模式”创建自己的令牌:

/**
 * Implementation of hook_token_info().
 */
function MODULE_token_info() {
  $info['tokens']['node']['node-term-path'] = array(
    'name'        => t('Node path by term'),
    'description' => t('The path to a node based on its taxonomy terms.'),
  );
  return $info;
}

/**
 * Implementation of hook_tokens().
 */
function MODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'node-term-path':
          $items = field_get_items('node', $node, 'TAXONOMY_FIELD_NAME');
          foreach ($items as $item) {
            $tids[] = $item['tid'];
          }
          if (in_array(TID_OF_TERM1, $tids)) {
            // Path for nodes with term1
            $replacements[$original] = 'word1/'. pathauto_cleanstring($node->title);
          }
          else {
            // Path for other nodes
            $replacements[$original] = 'content/'. pathauto_cleanstring($node->title);
          }
          break;
      }
    }
  }
  return $replacements;
}

找到了一个简单的方法,可以让任何需要类似解决方案的人使用模块实体引用

我刚刚为用户帐户创建了一个新字段selectentityreference,然后您可以选择drupal中的任何实体进行引用。 (即,您可以选择术语/内容/任何内容)