【问题标题】:Where is Drupal 7 termpath?Drupal 7 术语路径在哪里?
【发布时间】:2010-08-26 18:20:31
【问题描述】:

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

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

这个功能还不可用吗?

【问题讨论】:

    标签: drupal drupal-7


    【解决方案1】:

    在 Drupal 7 中,path 一词的含义非常具体,显然与 termpath 所指的含义不同,而且看起来没有为替换 [*path] 令牌而采取的措施(尽管这是一个已知问题):BIKESHED: Token for a term or menu item's entire tree/hierarchy

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

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

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

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

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            【解决方案5】:

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

            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 模式中。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-05-18
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-07-15
              相关资源
              最近更新 更多