When writing my custom function I need to manually append node name to a taxonomy term link. To get the taxonomy term part done I use:

  $link_uri = taxonomy_term_uri($term);
  $path_alias = drupal_get_path_alias($link_uri['path']);

This works ok, now - I want to append node name ("/" . $node_name), but instead of raw string, I want the Pathauto transliterated output, as set in the URL alias configuration, for that node context.

What function should I use to mimic that output? I looked at hook_pathauto_alias_alter(&$alias, array $context) but I'm not sure that's what I need.

  • By this, you want to have /taxonomy/term/1 and /taxonomy/term/1/nodename to point to the same page? I'm not sure what you really want as the first url points to the term while the second one includes a (which?) node name. – Paul Jan 16 '12 at 0:07
  • Sorry to be unclear: I know these are two different links. The goal of my code is to have /taxonomy/term/1/nodename. However I need the NOdENamE string (if you catch my point in the spelling) to pass through transliteration, so to have the result given by Pathauto. What would be the function for the transliteration then? AS per "which node?" - the code will be used on a node display, so the answer is THE node. The code I'm trying to write is a custom taxonomy link formatter. – Artur Jan 16 '12 at 1:03

If you want to filter your string the way pathauto does it, you can use pathauto_cleanstring():

module_load_include('inc', 'pathauto', 'pathauto');
$node_title .= pathauto_cleanstring($node->title);
| improve this answer | |
  • I tried using pathauto_cleanstring() in hook_menu(), which caused an error stating that the function didn't exist (even though the site in question has that module installed). As a work-around, the code used a regex to replace anything non-alphanumeric (except spaces) with a blank string, then replaced spaces with hyphens. It's perhaps not the best solution, but works well enough. – Agi Hammerthief Oct 11 '14 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.