0

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Michael D
  • 83
  • 2
  • 11

2 Answers2

2

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']));
SomeoneYouDontKnow
  • 1,289
  • 10
  • 15
0

To return the path alias, use drupal_get_path_alias

drupal_get_path_alias("node/" . $nid);
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105