Hi all. I've got nodes that are the destination of menu items. For instance, if I go to /admin/build/menu and edit a primary links menu item, I'll enter something like 'about/history' for the path. 'about/history' is defined as a URL alias for 'node/18'.

But, my menu is being displayed as 'node/18' instead of 'about/history'. Am I doing something wrong?

Thanks.

Comments

solson’s picture

I miss read your posting, sorry about that.

Nick Lewis’s picture

That's very odd. I'm guessing there is not an alias for one reason or another. If you go to admin/build/path can you see node/18 mapped to about/history? If the answer is yes, than the plot thickens.
--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.onnetworks.com

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.zivtech.com

tayknight’s picture

Yes, I see 'about/history' under the 'Alias column' and 'node/8' under the System column. I can navigate to both these paths.

Nick Lewis’s picture

Was that a mistype, or the solution? You say about/history maps to node 8, but earlier you said node/18 should map to about/history. You can't have both node/8, and node/18 map to about/history.

Of course, that may have been a mistype.... Let me know.

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.onnetworks.com

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.zivtech.com

tayknight’s picture

sorry. node/8 maps to about/history. Since i typed this, i've tried a couple more things.

I've emptied the url_alias, menu, and cache tables, and the menu still shows 'node/8' instead of 'about/history'. That info must be getting stored or cached somewhere else.

gpk’s picture

What happens if you put in node/18 as the path for the menu item?

On my site whether I put in node/x or url_alias, the menu item link is always of the form url_alias.

I wonder if a contrib module is imlicated. What happens if you disable everything except path and menu modules?

gpk
----
www.alexoria.co.uk

tayknight’s picture

I tried both your suggestions and neither worked.
The only modules I have active are Book (these are book pages), menu, and path.

Thanks for the help so far.

shanefjordan’s picture

I have a menu and the link is set to node/5027. I went and created a URL alias, existing path: node/5027, alias path: testing/aliasPath. I then went to the page that displays my menu and when I hover my mouse over the menu item, it shows the alias path and when I click on it, it takes me to the alias path. I did not have to change the path in the menu item (I left the link in the menu item to node/5027).

If you are changing the primary links menu, I noticed that I have to put in: index.php?q=testing/aliasPath for it to function properly. If I just put in testing/aliasPath, it will not work, because it does not have the index.php?q= prefix built into it when the page generates. Try to create a new menu, and see if the alias will work on that page. The only thing I can figure out, is that when it is doing the comparison for URL replacement, it finds index.php?q=node/5027 and doesn't realize that it needs to replace the node/5027 with testing/aliasPath.

Good Luck,
Shane

tayknight’s picture

This is a primary menu, so I'll try it with a different menu.

Thanks.

tayknight’s picture

Ok. I've created a new menu called 'Site_Menu'. I've created an item with a sub item. The sub item's path is 'about/history'. If i hover over the menu item, i see it is pointed to 'about/history'.

The path seems to be correct if I use it in a block. But this isn't what I want to do.

I'm creating a custom drop-down menu using a template.php function. If i do something like

$mymenu = menu_get_menu();
print_r($mymenu['visible'])

.
I can see the Site_Menu's Children, one of which is the id from the /admin/build/menu page. If i do something like

$mymenu = menu_get_menu();
$cid = $mymenu['visible']['children'][192] // this is the menu item I'm interested in.
print_r($m['visible'][$cid]);

then i'll get:

Array
(
    [title] => History
    [path] => node/8
    [children] => Array
        (
        )

    [type] => 118
    [pid] => 192
)

Notice the 'node/8' instead of the 'about/history' in the path. So, my question is why isn't the correct path being returned to the theme function, but it is if I use it as a block?

Thanks.

tayknight’s picture

In my theme function in template.php, i was calling menu_item_link. I don't think menu_item_link returns an alias, if one exists. I'll keep testing and post here about what i find.

gpk’s picture

Yes, URL aliases are not stored in the menu item itself - that only stores the actual internal "Drupal path". Conversion from internal path to URL alias is usually via by the url() function http://api.drupal.org/api/function/url/5, which in turn calls http://api.drupal.org/api/function/drupal_get_path_alias/5.

The HTML for the primary links is by default generated by:
http://api.drupal.org/api/function/menu_primary_links/5
which calls
http://api.drupal.org/api/function/menu_item_link/5
which calls
http://api.drupal.org/api/function/theme_menu_item_link/5
which calls
http://api.drupal.org/api/function/l/5
which in turn calls url().

So menu_item_link should return an alias, unless you have re-implemented theme_menu_item_link in your theme.

gpk
----
www.alexoria.co.uk

tayknight’s picture

Thanks for the info. I've certainly learned something today.

dkovacs’s picture

This problem can be solved by modifying your theme.
Add these lines to template.php in your theme's directory (in case of garland, it's in /themes/garland)

function phptemplate_menu_item_link($item, $link_item) {
  return l($item['title'], drupal_get_path_alias($link_item['path']), !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}

After this, the menu will contain URL aliases, even if you used the normal path creating the menu items.

Some background information, if you are interested in: if you enter a path alias when configuring the menu, the given path will be resolved to normal path while building the internal menu structure. (drupal_get_normal_path() call in _menu_build(), menu.inc:1036). The above lines are from theme_menu_item_link() (menu.inc:700) with some modification. I added drupal_get_path_alias() to the second parameter of l to display the URL alias instead of the normal link.

David

tayknight’s picture

Thanks, David for the info. I ended up doing it the way mentioned above (I'm displaying the menu as a styled dropdown, so I needed to do it in code).

Nico_0’s picture

I have the following code in my themes page.tpl.php to insert a seperator-image between the primary links:

<?php foreach ($primary_links as $menu_item_link): ?>
<?php

$href = $menu_item_link['href'] == "<front>" ? base_path() : base_path() . $menu_item_link['href'];
print "<a href='" . $href . "'>" . $menu_item_link['title'] . "</a>";

?><img src="/files/images/seperator.gif">

<?php endforeach; ?>

This works but the aliases do not appear.
I have put your code in the template.php but the aliases have not returned.

I have no idea what I should change to get to to work, do you have any suggestions?

Thanks!

giorgio79’s picture

I am getting this as well with the Zen theme (http://drupal.org/project/zen), and posted the issue there (http://drupal.org/node/299361)

I tried replacing Zen's phptemplate_menu_item_link in the template php but no luck, it did not help , any other ideas maybe?

keesje’s picture

Did some digging after encountering exact this problem in D6.

The cause in my project was a non english setup.
I enabled the core modules "Locale" and "Content translation".
Pathauto is installed en configured.
I added one other language (Dutch fyi) and added some content + menu items creating aliases automatically.
Later I switched the default language and the language of the #1 user profile back to English.

Somewhere after this point I noticed the problem, the menu, along with some other generated node links are pointing to node/nid, despite of the URL aliasses.

This is the case for all- and only Dutch content as I found out. I wasn't aware that the content was language specific at all, since I did not enable the option to translate content on node type level. The content seems to be automatically created in the current active language.

Solution:
I enabled "Enabled, with translation" in the "Multilingual support" fieldset for every node type. Now new content is set to "language neutral" by default. To fix existing nodes empty column "language" in table "url_alias" or resave all nodes as "language neutral".

Probably this is due to my incomplete multilingual setup (at some point a some content must be translatable).

Bottom line: I find it confusing that node types with translation options disabled are dynamically set to the current active language, without an option to alter this outside the DBS. It's not clear to me why the alias is discarded if the node is not in the current language. Is this a bug? Don't think so, not sure. This is at least something you should know when enabling core modules "Locale" + "Content translation" and add other languages.

Ubercart Webshop, Drupal website