Michael D
Michael D

Reputation: 83

Drupal menu_link with node/number instead of alias

I have a problem:

 function drupal_menu_link($variables) {
  $element = $variables['element'];

  $sub_menu = $element['#below'] ? drupal_render($element['#below']) : '';

  return '<a href="/drupal/'.$element['#href'].'" title = "'.$element['#title'].'" ><li' . drupal_attributes($element['#attributes']) . '>' . $element['#title'] .'</li></a>';
}

How can I base on aliases, not the hrefs? When I hover on an element I see node/number instead of alias. I made a redirection, but it happens after click. Can somebody help me? I was looking for that in other themes but I am bad at it and I just don't understand how it works.

Upvotes: 0

Views: 260

Answers (2)

SomeoneYouDontKnow
SomeoneYouDontKnow

Reputation: 1299

To transform an node/{number} - url to an existing url_alias, you could use the url method.

return '<a href="/drupal/'.url($element['#href']).'" title = "'.$element['#title'].'" ><li' . drupal_attributes($element['#attributes']) . '>' . $element['#title'] .'</li></a>';

A better way would be, to use the l method to generate the complete link:

return l($element['#title'], $element['#href'], array('attributes'=>$element['#attributes']));

Upvotes: 2

Muhammad Reda
Muhammad Reda

Reputation: 27023

To return the path alias, use drupal_get_path_alias

drupal_get_path_alias("node/" . $nid);

Upvotes: 0

Related Questions