Thanks for the great module. I did get it working with 4.6 and applied the patches from the tutorial to the taxonomy.module and the taxonomy_context module. The only thing that I was hoping was that distant parent could work properly with pathauto. I know there is a difference in philosophy (to some extent) between your patches and pathauto's functionality, but why not let distant parent work with both? Pathauto has a new api that might make it easier to tie into distant parent (not sure).

Right now, pathauto only finds the "distant parent" vocab and term and renders URL's based soley on the distant parent (not the "closer parent" vocab and term). Odd.

For now, I'm going to simply use taxonomy_context and pathauto and reconfigure my vocabulary.

CommentFileSizeAuthor
#1 pathauto.module.distantparent_aware.patch945 bytesJaza

Comments

Jaza’s picture

Assigned: Unassigned » Jaza
StatusFileSize
new945 bytes

This can easily be done, by patching pathauto so that it utilises the distant parent logic in the taxonomy patches (assuming that you've applied these patches - see the article at http://www.greenash.net.au/posts/thoughts/cross_vocab_taxonomy_hierarchies). All you need to do is modify the calls to the taxonomy_get_parents_all() function from authopath. I looked through the code in autopath, and the function is called three times. Here are the changes you need to make:

1. In _pathauto_generate_node_alias(), find this code:

      $catpath = '';
      $parents = taxonomy_get_parents_all($firsttermid);
      foreach ($parents as $parent) {
        $catpath = _pathauto_cleanstring($parent->name, $separator) . '/' . $catpath;
      }
      $placeholders['[catpath]'] = $catpath;

And replace with this code:

      $catpath = '';
      $parents = taxonomy_get_parents_all($firsttermid, TRUE);
      foreach ($parents as $parent) {
        $catpath = _pathauto_cleanstring($parent->name, $separator) . '/' . $catpath;
      }
      $placeholders['[catpath]'] = $catpath;

2. In _pathauto_generate_cat_alias(), find this code:

    if ($category->parent) {
      $catpath = $catname;
      $parents = taxonomy_get_parents_all($category->parent);
    } else {
      $catpath = '';
      $parents = taxonomy_get_parents_all($category->tid);
    }

And replace with this code:

    if ($category->parent) {
      $catpath = $catname;
      $parents = taxonomy_get_parents_all($category->parent, TRUE);
    } else {
      $catpath = '';
      $parents = taxonomy_get_parents_all($category->tid, TRUE);
    }

These are analogous to the "what's next, Dr Nick" patches, as explained in step 3 of the article. If you don't add the extra parameter with value TRUE, then the distant-parent-aware SQL query is not executed. This is so that the distant parent patch doesn't break the taxonomy module (which relies on terms being hierarchical only within one vocab, and which can't actually handle distant parent relationships).

I tested this patch on a clean install of 4.6, running the 4.6 branch of pathauto, and it generated distant-parent aware aliases for my categories and for my nodes just beautifully. To get aliases similar to the ones in my article, configure your default path pattern for nodes to be "[catpath]/[title]", and for categories to be "[catpath]" (this can be done on the pathauto settings page). Or adjust to suit your tastes!

Patch file for this is attached.

Jaza.

Jaza’s picture