It would be nice to be able to include the hierarchical path that results from hierarchical taxonomies. I have a vague idea of how this might work, but I can't seem to get it to work yet with a taxonomy_redirect_custom_term_path() function.

CommentFileSizeAuthor
#1 path_support.patch724 bytesAnonymous (not verified)

Comments

Anonymous’s picture

Assigned: Unassigned »
Status: Active » Needs review
StatusFileSize
new724 bytes

I think that I have achieved what I desired. I have included a patch file. I don't know if I generated the .patch file correctly; I used the diff command between a taxonomy_redirect_new.module and a taxonomy_redirect_old.module. Essentially, I added the option to enter "!path" in place of "!name" and "!tid". Let me know what you think. This is my first attempt to help with Drupal code after I got "Pro Drupal Development" for Christmas.

Anonymous’s picture

I should note that I'm trying to do this to set up an image gallery using Views. For example, I would like a view containing all photo thumbnails to show up at example.com/photos. Then I would like the view to take hierarchical taxonomy names as arguments. For example, example.com/photos/2007/event1 would filter the view down to photos that have been tagged with 2007>Event1 in the hierarchical taxonomy. I would also like the taxonomy links on each photo node to point to the appropriate filtered view. That's why I'm trying to get taxonomy redirect to produce hierarchical urls. I haven't quite got this all working, but I'm still trying to figure it all out.

edex13’s picture

Hi mikegoodwin,
your patch work with my installation. But i have minor problem. How i change all the case to lower case and change space to '-'.
righth now, it i use !path, it give me www.abc.com/Perhentian+Island. I prefer it to be www.abc.com/perhentian-island

thanks
edex

update:
i manage to get it to lower case. i not sure is it a proper way to do it.

-$catpath = $parent->name .'/'. $catpath;
+$catpath = $parent->name .'/'. $catpath;
+$catpath = drupal_strtolower($catpath);

please advice.

about the "+" symbol, i think this is not mikegoodwin's patch problem. I'll post is in taxonomy_redirect issue page.

thanks

mariagwyn’s picture

Mike, I have also applied the patch, and it works well, though I am having the same problem with the "+" sign above. My drupal installation does not like it at all in the URL, and initiates a search rather than going to the taxonomy page.

What i really want to do is use taxonomy_list to create a nice list of tax terms, which redirect to a views page which uses the same url as is created by your module patch. The problem is that neither my drupal install or views likes the "+", changing ".../liturgical+arts/iconography" to ".../liturgical%2Barts/iconography" which displays a "page not found" error.

Any suggestions?

Thanks,
Maria

Anonymous’s picture

I think that the "+" sign can be replaced with a "-" by using php's str_replace function, and the lowercase should be fixed using the above mentioned fix. So the code should look something like this:

<?php
function taxonomy_redirect_default_term_path($term, $path) {
  $parents = taxonomy_get_parents_all($term->tid);
  $catpath = '';
  foreach ($parents as $parent) {
    $catpath = $parent->name .'/'. $catpath;
  }
  //change to lowercase
  $catpath = drupal_strtolower($catpath);
  //replace + with -
  $catpath = str_replace('+', '-', $catpath);

  return t($path, array('!tid' => $term->tid, '!name' => $term->name, '!path' => $catpath));
}
?>

Obviously the php tags would not have to be included in the middle of your file. Let me know if that works for you.

mariagwyn’s picture

Mike

Sorry for the delay in response, I have been traveling. I applied the extra "replace" line, no effect. I am still getting the '+' sign.

Any other thoughts would be very appreciated! At this point, the only way to connect taxonomy and views is to change all my taxonomy terms to include '-' instead of spaces, which just looks bad on the pages.

Thanks,
Maria

mariagwyn’s picture

Solved!

I thought about your code a bit more, and realized that it was looking for an already existing '+' rather than a space. So, I updated the code, and with a little experimenting, this is what I currently have:

  //replace spaces in url with -
  $catpath = str_replace(' & ', '-', $catpath);
  $catpath = str_replace(' ', '-', $catpath);
  }

The first string is to replace the ampersand character I have in some of my descriptions, which was creating a url lik this: blah-%26-blah. Not pretty, doesn't work. So, by stripping the '&' first, I end up with blah-blah where the Taxonomy reads 'Blah & Blah.' Then, it strips the spaces. Note that this does not work if the order is reversed, since the spaces are stripped, and there is no ' & ' to find once that happens, so you still end up with a bad url.

Thanks for putting me on the right path...pun intended.

Maria

agileware’s picture

Status: Needs review » Fixed

Thanks for the patch.

5.x-1.2 now has two new path variables:
!parent_ids - replaced with the hierarchy of parent term ids
!parent_names - replaced with the hierarchy of parent term names

It also has a separator replacement option where you can provide a character that will replace all spaces and + characters in the path.

It also has a delete text option where you can provide a list of characters that you want removed from the path. You can use this to remove unwanted punctuation etc.

These features will also be added to the Drupal 6 version asap.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.