1

使用 Drupal 6 中的 pathauto 和 token 模块,您可以使用如下模式创建 url 别名:[termpath-raw]/[title-raw]。

然而,在 Drupal 7 中情况并非如此。我知道 D7 仍处于 alpha 阶段,但 beta 看起来很快就会出现,而且它比 D6 IMO 好得多。

这个功能还没有吗?

4

5 回答 5

3

在 Drupal 7 中,路径一词的含义非常具体,显然与termpath所指的不同,而且看起来还没有采取任何措施来替换[*path]标记(尽管这是一个已知问题):BIKESHED :术语或菜单项的整个树/层次结构的标记

它看起来也不会成为核心,并且会成为 contrib Token 的一部分,甚至#D7CX-pledged 项目也必须在最终发布之前完成他们的 Drupal 7 端口,这可能接近于年。

于 2010-08-26T19:53:54.310 回答
1

令牌模块共同维护者在这里。这里还有更多工作要做,因为分类标记不是很简单。它们现在是字段,我们还没有为 D7 字段编写令牌支持。这是我们必须完成的事情。

于 2010-09-23T00:16:46.860 回答
1

几个月来,我一直在思考这个问题,我终于找到了一个似乎可行的解决方案:

http://drupal.org/node/741914#comment-5025862

简而言之,我创建了一个自定义模块,它公开了一些额外的标记(可以在页面标题或 pathauto 等模块中使用)。在代码隐藏中,标记被节点或分类术语的完整分层分类路径替换(有针对 url 的标记和针对页面标题的其他标记)。

实际实现可以在链接页面的讨论中找到。

我希望这可以帮助一些人用他们自己的实现。

于 2011-09-23T07:45:31.430 回答
0

您可以将taxonomy_entity_index模块与问题队列中的补丁一起使用。唯一真正糟糕的是您必须使用 Drush 命令在工作站点上构建索引或以某种方式重新导入当前站点的内容。

于 2012-09-28T13:26:25.590 回答
0

我不记得我在哪个沙盒项目中找到了这个,但它是完美的解决方案。

taxonomy_path_token.info

name = Taxonomy Path Token
description = Taxonomy path token creates a path of parent taxonomy terms of a node
package = Token 
core = 7.x

dependencies[] = token

taxonomy_path_token.module

<?php

/**
 * Implements hook_tokens().
 */
function taxonomy_path_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if (!empty($tokens['taxonomy_path']) && !empty($data['node'])) {
    if(!empty($options['sanitize'])) {
       $sanitize = $options['sanitize'];
    } else {
      $sanitize = FALSE;
    }

    $node = $data['node'];
    $replacements[$tokens['taxonomy_path']] = $sanitize ? check_plain(taxonomy_path_token_get_parents($node)) : taxonomy_path_token_get_parents($node);
  }

  if ($type == 'array' && !empty($data['array'])) {
    $array = $data['array'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'join-path-except-first':
          module_load_include('inc', 'pathauto');
          $values = array();
          foreach (element_children($array) as $key) {
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = pathauto_cleanstring($value);
            $values[] = $value;
          }
                    array_shift($values);
          $replacements[$original] = implode('/', $values);
          break;
      }
    }
  }

  return $replacements;
}

/**
 * Implements hook_token_info().
 */
function taxonomy_path_token_token_info() {
  $info['tokens']['node']['taxonomy_path'] = array(
    'name' => t('taxonomy_path'),
    'description' => t('Custom taxonomy_path token.'),
  );

    $info['tokens']['array']['join-path-except-first'] = array(
    'name' => t('Joined path'),
    'description' => t('The array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.'),
  );

  return $info;
}

function taxonomy_path_token_get_parents($node) {
  module_load_include('inc','pathauto','pathauto');

    if(!empty($node->field_tags)){
        $tid = current($node->field_tags);
        $tid = $tid[0]['tid'];
    }
    else{
     return '';
    }

  $parents = taxonomy_get_parents_all($tid);
  $paths = array();

  foreach ($parents as $parent) {
    $paths[] = pathauto_cleanstring($parent->name);
  }

    $paths = array_reverse($paths);
    array_shift($paths);
  $pathauto = implode('/', $paths);

  return $pathauto;
}

然后将此“[node:taxonomy_path]/[node:title]”添加到您的 pathauto 模式中。

于 2012-12-05T13:22:42.810 回答