Using path aliases with menu paths

doudou - November 15, 2007 - 16:10
Project:Taxonomy Menu
Version:5.x-1.04
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I couldn't find a similar issue previously posted. Basically I use Taxonomy Menu to update all of my menu structures. However pathauto would not rename the menu paths. For example a menu path may look like this: /taxonomy_menu/3 instead of something meaningful like /blog/drupal.

#1

greggles - November 15, 2007 - 17:05
Project:Pathauto» Taxonomy Menu
Version:5.x-1.2» 5.x-1.x-dev

This is something that the taxonomy menu module would have to implement. For example code see how this is done for the blog module in pathauto_user.inc

You just need to implement two hooks.

#2

levavie - November 19, 2007 - 09:02
Status:active» needs review

As a temporary solution, I've written a module which uses custom_url_rewrite to change all taxonomy_menu URLs to the correct taxonomy/term/... form, and works with pathauto URLs.

This works great on the top nice_menus on my site, http://levavie.com

rewrite.module may be downloaded from here: http://drupal.org.il/sites/drupal.org.il/files/rewrite.tar.gz

Here is the code, adapted from the multidomain module:

<?php

if (!function_exists('custom_url_rewrite')) {

  function custom_url_rewrite($type, $alias, $real_path) {

    $path = ( $alias ) ? $alias : $real_path;
    $parts = explode('/', $path);
    if ($parts[0] == 'taxonomy_menu') {
      $path = 'taxonomy/term/'. end($parts);

      $result = db_query( "SELECT dst FROM {url_alias} WHERE src= '%s'", $path);
      while ($row = db_fetch_object($result)) {
        $path = $row->dst;
        break;
      }

    }
    return $path;
  }     
}        
else {  
   drupal_set_message('error', t('The rewrite module has found a custom_url_rewrite function that is already defined. This conflicts with the module\'s operations, and as such the rewrite module will not work'));
}           

Enjoy,

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | Effective Hosting Strategies | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

#3

levavie - November 19, 2007 - 09:10
Status:needs review» needs work

#4

giggler - February 17, 2008 - 02:35

How is this used after installing the module?

#5

Murz - March 24, 2008 - 15:04

I add some support for pathauto module in my patch Patch for remove vid or module page from url (with pathauto support), you can try to use it.

#6

Jeroen Coumans - April 16, 2008 - 23:00

This works great, but its behaviour is slightly different from taxonomy menu: for terms with subterms, the children aren't displayed anymore.

#7

Murz - April 17, 2008 - 10:48

This is work on my drupal 5.2 versions with subterms good. You can look at it on my development site http://gr.shtrix.ru/articles/kimberly-clark/ripple
If you use menu block split module, it have an issue that can be solved width this patch.

#8

fallsemo - June 18, 2008 - 14:29

subscribe.

#9

q0rban - August 11, 2008 - 20:06

Sorry everyone, I don't know why I didn't see this before posting another request and patch for this feature. You can download the patch here.

#10

pelicani - September 8, 2008 - 16:19
Status:needs work» needs review

The link above is to a duplicate issue.
A duplicate of this issue.
So if you follow the logic, as I did, you get in an infinite loop.

We are looking for taxonomy_menu to honor the pathauto settings.
I believe this patch should do this.
I have yet to test, but here it is.
*Taken from dupe issue listed as #9 above*

AttachmentSize
taxonomy_menu_pathauto_0.patch.txt 5.66 KB

#11

q0rban - September 8, 2008 - 16:36

Man, how did you break out of that loop!

;)

Sorry, I guess my link was a bit misleading as it linked to the issue that had the file attached, and not the actual file itself.
Here's the correct link.

#12

Summit - September 12, 2008 - 16:47

Subscribing, looking for an option to use depth to change the url build like taxonomy/term..
greetings,
Martijn

#13

alliax - November 4, 2008 - 08:44

What a bad surprise to realize that taxonomy menu module is creating duplicate content on my site because I already use pathauto and this module doesn't care about aliases and uses it's own path. So I end up with two urls in google for the same page, how bad... What were the developpers thinking when they choose not to support pathauto? Incredible!
Please someone correct this, the issue has been going on for over a year, it looks like someone doesn't want this BUG to be fixed!

#14

greggles - November 4, 2008 - 13:10
Title:Using pathauto with menu paths» Using path aliases with menu paths

It's not really a matter of "not supporting pathauto" it's a matter of not supporting path aliases in general (since pathauto is just a wrapper around the core path system).

But yes, I agree...bump?

#15

Summit - November 4, 2008 - 14:29

Hi,

Not wanting to hijack this thread, but asking for considering keeping also the present functionality
The great thing from taxonomy_menu is the fact that the hierarchy of the terms is showed in the url.
I build a very small function on this to be able to use different panels at different term level.

See www.wintersport-accommodaties.nl for a example of my use of the taxonomy_menu module.
http://www.wintersport-accommodaties.nl/land-info/Frankrijk
land-infoIs the taxonomy_menu /VID/TID panel
http://www.wintersport-accommodaties.nl/gebied-info/Espace-Killy
gebied-info is the taxonomy_menu /VID/TID/TID panel

Hopefully a solution can come up to use path aliases, but still be able to use the /VID/TID/TID etc.. functionality from taxonomy_menu which I now use.

Greetings, Martijn

#16

asak - November 19, 2008 - 20:21

So... does any of this work?

EDIT: WORKS!

Thanks for this patch... it's a site saver ;)

(Patch from #10 / #11)

#17

asak - November 19, 2008 - 21:32

Is there a special reason why the token [catpath-raw] isn't working?

I can see it in the Replacement patterns for the "catalog path" in pathauto, and would very much like it to work with taxonomy menu!

;)

#18

Falldog - December 4, 2008 - 04:19

Subscribe

#19

joyltd - December 16, 2008 - 10:08

Hi there...may I start with the common, "I'm a bit of a Newbie here - please don't attack me" approach!?

Got a stupid question:
pelicni, thanks for that patch - I reckon its going to be just what i need judging on what asak says.
So...and here's the stupid part, where do I place the patch!!
I've guessed that it goes in the taxonomy_menu.module file, but do i just paste the whole lot of the patch at the bottom of the taxonomy_menu.module file?

ps: last time I tried to patch a module I managed to break it!

Thanks in advance, this documentation at drupal is some of the best I've come across - and I love my new drupal buddies! Your expertise is much appreciated.

#20

Summit - December 16, 2008 - 12:21

Hi Joy,

Welcome!
For your question. No you need to patch your taxonomy_menu.module using patching software.
If it is a small patch I prefer looking up the old code (the one with - before it), and paste the new code (the one with + before it).
Off course you break the module keeping the + signs there. They are not php-commands. You have to erase those.

Greetings,
Martijn

#21

stoltoguzzi - December 16, 2008 - 20:57
Title:Using path aliases with menu paths» for D6?

is this patch for D6 as well!

#22

greggles - December 17, 2008 - 00:24
Title:for D6?» Using path aliases with menu paths

#23

joyltd - December 17, 2008 - 12:44

Thanks Summit.

I've found it! Thanks - in true newbie fashion I was searching under the wrong criteria yesterday...now about to warm up the command line in Terminal!

All the best

PS: to answer my own question some what, I found an excellent video tutorial here - yeah its to do with testing patches under Drupal Head - but all the info i need is there.

#24

doofaye - December 26, 2008 - 13:06

can someone let me know if patch in #9 #10 solves problems with duplicate content in website?
the patch gives ability to alias taxonomy menu to whatever you want but the system paths are still different to taxonomy/term/

basically after applying patch #9,10 does this solve duplicate content issue???????

#25

fumbling - January 3, 2009 - 14:38

Looks like you were replying on whether there was a patch for D6, but don't see a response. In any event, any plans for a D6 patch?

#26

indytechcook - February 1, 2009 - 04:21

Please respond if the patch works and I will create a release for it

#27

indytechcook - February 3, 2009 - 13:49

I'm leaning towards committing #234513: Path Auto Support in a new D5 Dev version. If anyone that uses the patch on this page is object to that then please respond by 2/5. Note that the other patch includes functionality to hid the vocabulary.

#28

indytechcook - February 10, 2009 - 13:38
Status:needs review» fixed

This is part of the latest DEV. Please test. Implemented in conjunction with #234513: Path Auto Support

#29

jstirnaman - February 11, 2009 - 16:46

When I tried to run the Pathauto batch operation for taxonomy_menu, it couldn't find taxonomy_vocabulary_load() which is called at line 99 in taxonomy_menu_pathauto.inc. I'm still running Drupal 5.11. I made the following change and it's working fine:

      $vid = $category->vid;
      //$vocabulary = taxonomy_vocabulary_load($vid);
      //Replace above function call with this one per http://drupal.org/node/333661. Not sure why the difference? -- jstirnaman
      $vocabulary = taxonomy_get_vocabulary($vid);

#30

greggles - February 11, 2009 - 18:02
Status:fixed» active

http://api.drupal.org/api/function/taxonomy_vocabulary_load is a 6.x+ function. The 5.x version of the code will need to use taxonomy_get_vocabulary.

#31

indytechcook - February 11, 2009 - 19:11

I will update this tonight and a new DEV package will be release overnight.

#32

jstirnaman - February 11, 2009 - 20:52

After a few more minutes, I realized it's not quite right. Maybe I'm doing something wrong, but pathauto is adding a preceding slash to taxonomy_menu terms when there is no module page value set. The result is that the menu ignores those menu items. If I remove the preceding slash in URL Aliases the links display and work properly. I don't know that this is a proper solution, but I made the following hack to taxonomy_menu_pathauto.inc and the paths came out properly:

$path =  variable_get('taxonomy_menu_display_page', 'category') . $category->vid;     //Removed . '/' . -- jstirnaman

#33

indytechcook - February 12, 2009 - 13:16
Status:active» fixed

Changes have been made to latest Dev package. Thanks jstirnman.

#34

ahmaddani - February 26, 2009 - 04:11
Version:5.x-1.x-dev» 5.x-1.04
Assigned to:Anonymous» ahmaddani
Status:fixed» active

This comment is reply from #15

Please explain me how you do that. I think your site has prety taxonomy hierarchy.

#35

ahmaddani - February 26, 2009 - 04:09

Please explain me how you do that. I think your site has prety taxonomy hierarchy

#36

Summit - March 4, 2009 - 21:12

Guys,
This custom_url_rewrite is working on D5. How to get it working in D6 please?

<?php
function custom_url_rewrite($type, $path, $original) {
# vocabulary = 5
$vid = 5 ;
$newpath = $path;
$depth = 0;

// This path was already aliased, skip rewriting it
if ($path != $original) {
  return
$path;
}

// Rewrite to custom url:
 
elseif ($type == 'alias') {
  if (
substr($path, 0, strlen("taxonomy_menu/")) == "taxonomy_menu/") {
 
$termid = substr($path, strlen("taxonomy_menu/"));


 
$tids = explode("/", $path);
   if (
is_numeric($tids[4])) {
    
$term = taxonomy_get_term($tids[4]);
    
$newpath = "city-info/". $term->name."/";
   }
   elseif (
is_numeric($tids[3]))  {
    
$term = taxonomy_get_term($tids[3]);
    
$newpath = "region-info/". $term->name."/";
   }
   elseif (
is_numeric($tids[2]))  {
    
$term = taxonomy_get_term($tids[2]);
    
$newpath = "country-info/". $term->name."/";
   }  
  
  }
}
// Nothing to do:
return $newpath;
}
?>

#37

indytechcook - March 5, 2009 - 13:38
Assigned to:ahmaddani» Anonymous
Status:active» fixed

Setting backed to fixed since issue is resolved.

#38

System Message - March 19, 2009 - 13:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.