Hi,
Trying to get taxonomy_menu giving the right menu trail.
1) I have a correct taxonomy_menu working, using views:category and hierarchical menu path.
2) It is expanding correctly usnig normal taxonomy/term url-paths
3) I change the /VID/TID/TID/TID to nice hierarchical url's using the following snipper in settings.php

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
   //The vocabulary which needs url_rewrite with taxonomy_menu enabled
   $vid = 4;
     // Get ID's: [VID]/[TID]/[TID]etc.. out of taxonomy_menu and place them in $matches ARRAY
    if (preg_match('|^category(/.*)|', $path, $matches)) {

      //If the $vid matches the [VID] within the taxonomy_menu ARRAY then url rewrite
       if ($matches[1] = $vid) {
           $ids = explode("/", $path);

           if (is_numeric($ids[4]))  {
             $term_land = taxonomy_get_term($ids[2]);
             $term_regio = taxonomy_get_term($ids[3]);
             $term_plaats = taxonomy_get_term($ids[4]);
             $path = "regio/".$term_land->name."/".$term_regio->name."/".$term_plaats->name;
           }
           elseif (is_numeric($ids[3]))  {
             $term_land = taxonomy_get_term($ids[2]);
             $term_regio = taxonomy_get_term($ids[3]);  
             $path = "regio/".$term_land->name."/".$term_regio->name;
           }
           elseif (is_numeric($ids[2]))  {
             $term_land = taxonomy_get_term($ids[2]);
             $path = "land/". $term_land->name;
           }   
           elseif ($path <> '') {
               $path = 'node';
           }
            $options['base_url'] = 'http://www.top-vakantie-aanbiedingen.nl';
            $options['absolute'] = true;
       }
    }   
}

The only problem is that it is not expanding correct to the right term-level. I have the levels:

--country
----region
---------city

When the active menu-item is a country term, it is not expanding the underneath terms. And when the active term is on region or city level, the menu is not expanding at all.
To be honest, it is expanding nothing..

See for example the bottom menu on the right sidebar of http://www.campings-europa.com

I hope this module can help to get my taxonomy_menu expanding correct!
Thanks a lot for your support in advance.
greetings,
Martijn

Comments

Summit’s picture

I forgot that in dutch country means "land". The top-url's of the taxonomy_menu are:

country/France -> land/Frankrijk
country/Holland -> land/Nederland

Sorry for that. Hopefully you guys can help me!
greetings, Martijn

Dmitriy.trt’s picture

Did you also implemented custom_url_rewrite_inbound(...) ?

Summit’s picture

Hi Dmitriy, No I didn't implement custom_url_rewrite inbound(..), should I, how should the code then look like?
Thanks for your quick reply!
greetings, Martijn

Dmitriy.trt’s picture

According to API examples:
http://api.drupal.org/api/function/custom_url_rewrite_outbound/6
http://api.drupal.org/api/function/custom_url_rewrite_inbound/6
function custom_url_rewrite inbound(..) should restore path to its original state, like it was before processing by custom_url_rewrite_outbound(..). I didn't even know about these functions before, so I can't say exactly how it should work.

Also, take a look at long standing bug about menu expanding. You can use patch or just apply my recommendation for this bug by hands to test it.

edit: Sorry, of course You already know about this bug.

Summit’s picture

Hi Dmitriy,
1) First, I off course want to change the urls VID/TID/TID to hierarchical levels:

--country
----region
---------city

S0 I think using the inbound, will change it back or something right?

2) I tried your patch

Also, take a look at long standing bug about menu expanding. You can use patch or just apply my recommendation for this bug by hands to test it.

But it didn't change anything. Applied the patch to http://www.campings-europa.com (it is installed in the codebase right now...

Thanks for helping me further in advance.
greetings,
Martijn

Dmitriy.trt’s picture

Please, try to implement custom_url_rewrite_inbound function, so system gets original urls.

Also, please, try both inbound function and patch together. Patch is necessary because your view's path has less parts than actual urls. You've probably set view's path to something like "category/%/%", but with url "category/1/2/3" it will not work without patch.

Summit’s picture

Hi,
I found this example:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  global $user;

  // Change all article/x requests to node/x
  if (preg_match('|^article(/.*)|', $path, $matches)) {
    $result = 'node'. $matches[1];
  }
  // Redirect a path called 'e' to the user's profile edit page.
  if ($path == 'e') {
    $result = 'user/'. $user->uid .'/edit';
  }
}

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  global $user;

  // Change all 'node' to 'article'.
  if (preg_match('|^node(/.*)|', $path, $matches)) {
    $path = 'article'. $matches[1];
  }
  // Create a path called 'e' which lands the user on her profile edit page.
  if ($path == 'user/'. $user->uid .'/edit') {
    $path = 'e';
  }
}

But will the url itself not show /[VID]/[TID]/[TID] if I rewrite them back to the original /VID/TID/TID what taxonomy_menu hierarchical url's are.
The point is that I want per depth, which is build up bij amount of /TID/TID/TID's in the url a different rewritten url, like /TID = country, /TID/TID = region and /TID/TID/TID = city.

greetings,
Martijn

Dmitriy.trt’s picture

As I understand, these two functions are used together to get nice readable visible url without broken handling of this url. System gets normal url and handle it right, users have their readable url. These functions are similar to path aliases and should be used together.

Summit’s picture

So you are saying that I need to build the url's back to their normal /VID/TID etc..form with custom_url_rewrite_inbound? But isn;t the url itself not shown than again as /VID/TID instead of land/[term_name]?

Dmitriy.trt’s picture

Status: Active » Closed (works as designed)

Please, read documentation to these functions carefully. Problem is not in Taxonomy Menu Trails. If implementing correct functions with patched core will not help, feel free to reopen this issue.

Summit’s picture

Ok will do. Thanks for your input! Greetings, Martijn