I have nodes with the taxonomy term Term1 associated (TID1).

The normal breadcrumb is
Home > Term1 (titles)
/ > /taxonomy/term/TID1 (URLs)

I'm using taxonomy_redirect to replace the URL /taxonomy/term/TID1 by /panel/TID1 (using a Panel taxonomy override is not an option in my case), so it becomes
Home > Term1 (titles)
/ > /panel/TID1 (URLs)

Now I have a view page taking a term id as argument on /view/TID1

I'm using a custom_breadcrumb_view to provide a breadcrumb for that view
[term] (titles)
taxonomy/term/[term-id] (URLs)

I get this breadcrumb
Home > Term 1 (titles)
/ > /taxonomy/term/TID1 (URLs)

which is OK for custom_breadcrumbs_views but with my taxonomy_redirect I should have instead
Home > Term1 (titles)
/ > /panel/TID1 (URLs)

I tried to set the weight of taxonomy_redirect to 200 to make it execute after custom_breadcrumbs_views but with no success.

taxonomy_redirect uses hook_term_path() to change the terms links in the breadcrumb.

taxonomy_redirect replaces well the term link for a view with a TID argument when I don't have any custom_breadcrumbs_view for that view.

My issue is quite complex and I'm sorry for that MGN, I hope I explained it right. Do you have any idea of what's happening ?

Comments

MGN’s picture

I am not sure I understand the problem, but here is a shot at it.

Taxonomy redirect doesn't create aliases for terms, it modifies the links returned by taxonomy_term_path(). It won't affect the breadcrumb links that you specify for the view breadcrumb. But since you are setting up the breadcrumb for this view, you can set up the redirect yourself in the breadcrumb - do something like:

Titles:
[cat]

Paths:
panel/[tid]

(Note that you can use the taxonomy object tokens with the latest dev code for views that use taxonomy arguments)

I think this would work for you, but let me know if it doesn't.

MGN’s picture

Category: feature » support
guillaumeduveau’s picture

Category: support » feature

You understood well MGN, thanks again ! So the problem is that custom_breadcrumbs_views does not call taxonomy_term_path, and I understand it should not, since views can have no taxonomy at all (args or nodes returned by the view).

Yes I could use panel/[tid] directly when setting up the breadcrumb, however I would need 2 views instead of one, because I want to redirect the terms to panels sometimes, sometimes I want to leave the normal taxonomy pages. But it is doable.

A last approach would be to add a redirect form /taxonomy/term/TID1 to /panel/TID1 but path_redirect won't let me do that, so it must be in .htaccess.

MGN’s picture

Category: feature » support

I can't think of a way of adding this as a feature in custom breadcrumbs. But you should be able to do it using tokens.

First, have you tried [catpath] and [catalias]? I expect [catpath] will not give what you are looking for because it is probably aliased to taxonomy/term/% via pathauto. [catalias] also returns the aliased path, so I don't think it will work either. Nevertheless, I'd give both a try just to be sure I am thinking about this correctly.

So it seems like you need to create a new token to return taxonomy_term_path() for the path.

This is easy enough to do in tokenSTARTER.module (included in the token module).

I am not sure what to call this new token - how about [category-term-path] (since [catpath] and [termpath] are both taken)

in tokenSTARTER_token_list() you'll want to describe the new taxonomy-based token after the node tokens. Something like...

  ...
  if ($type == 'node' || $type == 'all') {
    // Node tokens here.
  }

  if ($type == 'taxonomy' || $type == 'all') {
    // Taxonomy tokens here.
    $tokens['taxonomy']['category-term-path'] = t('The path returned by taxonomy_term_path.');
  }

  return $tokens;
}

And in tokenSTARTER_token_values() you'll need to call taxonomy_term_path to assign the token. So something like

    ...
    case 'node':
      // Node tokens here.
      break;
    case 'taxonomy':
      // Taxonomy tokens here.
      $values['category-term-path'] = taxonomy_term_path($object);
      break;

  }
  return $values;
}

Now you've got a new token [category-term-path] which you can use in custom breadcrumbs or any other module that uses tokens.

MGN’s picture

Status: Active » Closed (fixed)

Closing this since the question has been answered.