0

I'm trying to use the links__system preprocess function to output a menu as a select element, unfortunately though $link['href'] appears to output the URL in a format like:

node/2

Even though the URL alias is set to something like:

nice-url

The code I'm using in my template.php file is as follows:

function THEME_links__system_MENU_NAME($variables) {
  $html = '<select name="" id="dropdown-menu">';
  $html .= '<option class="" value="home">Select Item</option>';
  foreach ($variables['links'] as $link) {
    $html .= '<option class="" value="' .$link['href'].'">'. $link['title'] .'</option>';
  }
  $html .= '</select>';

  return $html;
}

I've had a look at the $variables variable passed to this function, just to make sure I'm not referencing the wrong thing - but it doesn't appear to contain any other items in the array that contain the correct URL alias.

When using the default menu code output by Drupal it picks up the URL aliases and uses them.

What am I doing wrong here?

0

I managed to get around this by using the drupal_get_path_alias function in the end, so my resulting code was:

function THEME_links__system_MENU_NAME($variables) {
  $html = '<select name="" id="dropdown-menu">';
  $html .= '<option class="" value="home">Select Item</option>';
  foreach ($variables['links'] as $link) {
    $html .= '<option class="" value="'. drupal_get_path_alias($link['href']) .'">'. $link['title'] .'</option>';
  }
  $html .= '</select>';

  return $html;
}

Dissapointed I didn't think to search for such a function in the first place!

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.