User login

Override taxonomy/term style links for a custom (module-owned) vocabulary

(Solution at bottom.)

Agaric's initial test implementation hook_link_alter indicated that it doesn't quite act however the module w

/**
* Implementation of hook_link_alter, a hook so secret DPD doesn't cover it.
*/
function place_taxonomy_link_alter(&$node, &$links) {
drupal_set_message('' . print_r($links, TRUE) . '');
foreach ($links as $module => $link) {
if (strstr($module, 'place')) {
// Link to the place panel and not the taxonomy term page. We'll only
// do this if the taxonomy term in question belongs to Place.
$tid = str_replace('taxonomy/term/', '', $link['href']);
$term = taxonomy_get_term($tid);
// this requires creating a panel called places!
if ($term->vid == place_taxonomy_get_vid()) {
$links[$module]['href'] = str_replace('taxonomy/term', 'places/' . $term->weight, $link['href']);
}
}
}
}

As our drupal_set_message output tells us (tip: don't use lines like that in production code!) the output for regular taxonomy terms do not give us the module name, but rather a string of "taxonomy_term_" with a term ID number attached.

Array
(
[taxonomy_term_87] => Array
(
[title] => Globe Friends
[href] => taxonomy/term/87
[attributes] => Array
(
[rel] => tag
[title] =>
)

)

...
)

Worse, hook_link_alter is only run for nodes – from a home page that has a whole huge tag cloud on it, this is all we get:

Array
(
[node_read_more] => Array
(
[title] => Read more
[href] => node/52
[attributes] => Array
(
[title] => Read the rest of this posting.
)

)

)

So hook link alter is clearly not the right approach.

Now, there's a module specifically for redirecting taxonomy terms out there, and there's also the panels_taxonomy module, which must also deal with this. Not sure how they do it.

Here's how Agaric's doing it for place_taxonomy, because the vocabulary we're interested in owned (err, collectively managed and operated?) by our very own place_taxonomy module. That gives us a special hook, which is quite well documented on page 230 of Drupal Pro Development:

Resolution

/**
* Implementation of hook_term_path
*
* For now, this is a hack: if you don't have a panel set up to receive
* taxonomy terms at the URL places, it will simply be broken
*/
function place_taxonomy_term_path($term) {
return 'places/' . $term->tid;
}

Searched words: 
change taxonomy links alter term link

Comments

LACKING

I have read many of your pages and while it is nice you took the time, they really lack a great deal. It would be a good idea to give people an idea of a starting point as your post always seem to begin mid-thought.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.