When I set the default path pattern to

pathraw/[menupath-raw]/menuraw/[menu-raw]/titleraw/[title-raw]

and I create an "our history" page under home/company/about/, I get the following alias created:

pathraw/menuraw/titleraw/our-history

i.e. [menupath-raw] and [menu-raw] don't seem to work. Is this a pathauto issue or a token issue, or something else entirely?

This is with Pathauto 6.x-1.x-dev and Token 6.x-1.x-dev, both up to date.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Project: Pathauto » Token
Component: Miscellaneous » Code

Reassigning to token - the problem is in token_node.inc, which references global $_menu (no longer there). The menu implementation has been totally reworked for Drupal 6, so this section of the code needs a rewrite. I'm taking a look now...

mikeryan’s picture

Unfortunately, today's the last day I had a good chunk of time for development until after Drupalcon, and I didn't get to the point of producing a solution - I need to dig into the documentation a bit farther. I think it should be fairly easy to pull the necessary info out of the menu_links table.

aaronshaf’s picture

This is a huge problem, and makes Drupal 6 pretty much unusable for me.

gerritvanaaken’s picture

Would be great if we could use this feature in D6. I’ll be grateful!

mbond’s picture

Any ETA on a fix for this?

I'm still too new to developing drupal modules to take a serious stab at coming up with a patch myself.

Thanks,

mikeryan’s picture

Assigned: Unassigned » mikeryan

Sorry, I was away for a few days, now I'm covering my day job while attending Drupalcon... The menu system was totally redesigned for Drupal 6, so this section of the token code needs to be completely written. I can probably throw together a quick patch tomorrow night (caveat emptor - many caveats) if people are desperate, but it'll take more time for me to get comfortable enough with the new menu system and test thoroughly enough to provide something releasable.

mbond’s picture

That would work for me at this point.

We're evaluating drupal as a replacement CMS, i can't move forward until i can satisfy people that the URLs being auto-aliased is doable. I'm stuck between a rock and a hard place of "demonstrate that drupal works, or start writing an in house CMS"

a quick hack would do wonders to my work load :).

mikeryan’s picture

Status: Active » Needs review
FileSize
4.65 KB

OK, I've got a patch which also fixes the book token issue... Still more testing to do, but for the moment give it a shot...

mbond’s picture

Works like a champ so far, limited testing.

Thanks.

imclean’s picture

No joy with the patch here I'm afraid, although it did make some changes to the results.

Versions:
- Drupal 6.1
- Pathauto 6.x-1.x-dev
- Token 6.x-1.x-dev
- The above patch

Using [menupath-raw], it generates a path based on the first item in Primary Links even if the page is added at the same level. So, if "About Us" is the first in the list, the paths would be "about-us-0", "about-us-1" etc. for the other items regardless of depth. Adding /[title-raw] to it simply adds the page title to the path as expected. e.g. about-us-0/products even if Products is at the same level as About Us.

A related question, does [menupath-raw] include [title-raw] as I think it did in 5.7 or should the path be written [menupath-raw]/[title-raw] now? If the latter, that could cause problems with the top level of a menu.

greggles’s picture

Status: Needs review » Needs work

@imclean - I think including title-raw into menupath-raw was a short term bug in token that (hopefully) got fixed...

Updating status to reflect imclean's comments.

greggles’s picture

Actually - perhaps this is a misunderstanding about title-raw being part of menupath-raw or not and the code is ready to go.

sonnen’s picture

Status: Needs work » Needs review
FileSize
5.25 KB

I've attached an alternative patch similar to mikeryan's, but with a different method of deriving the menu path to address imclean's bug notes. It also exposes a new token - menu-link-title (and -raw) showing the menu link text.

I didn't include mikeryan's book token fix just to keep the patch easier to review.

mikeryan’s picture

Thanks, I'll take a look at your approach. My goal is to commit a final patch for these two issues this weekend...

imclean’s picture

Thanks for the informative responses. I've updated to the following versions:

- Drupal 6.2
- Pathauto 6.x-1.x-dev (2008-Apr-14)
- Token 6.x-1.x-dev (2008-Apr-09)
- sonnen's patch (post #13)

Everything is now working beautifully. I'll keep an eye on things but at this stage the above seems to do the business nicely.

mikeryan’s picture

I've committed the last patch from http://drupal.org/node/223458 - I've let these issues lie too long, and it's at least a major improvement over the current state. It does not include sonnen's patch in #13 - @sonnen, can you reroll your patch against the current CVS?

Thanks.

sonnen’s picture

Here's the patch from post #13 above re-rolled against the current HEAD version. This incorporates the menu path fixes, and the new menu-link-title tokens.

Sorry for the delay on that. Thanks,
Richard

imclean’s picture

greggles, the current dev version (2008-May-04) does include title-raw in menu-path-raw but otherwise appears to work fine. sonnen's patch in #17 obviously doesn't work with this version.

Edit: it seems there are still some problems with determining the correct path to the current page from the menu. In my case, a top level page includes the path of the first top and second level.

E.g.

Services is a top level menu item

- about - history
- about - history - services

Frank Steiner’s picture

Hmm, with the new release without sonnen's patch nothing changed here. Using [menu-raw][title-raw] as pathauto-pattern, I still get only http:/ /mysite/[title-raw] aliases for new pages, no matter how deep the page is in the menu tree...

mikeque’s picture

FYI:
[menu-raw] and [menupath-raw] are also failing with the custom breadcrumb module

fletchgqc’s picture

I'm using menu breadcrumb module and experiencing this issue with the 2008-May-10 dev Token release. I guess that's not very helpful as you are just waiting for mikeryan to check sonnen's patch but anyway, hopefully better than "subscribe".

If someone rolls the patch against this version or say current CVS Head I should be able to test it.

Frank Steiner’s picture

Here's sonnen's patch against the May version. However, I'm not sure it that's the intended way because the _menu_titles function is completely different and the patch just replaces it as a whole.

It does work for the pathauto module which is the only way I use it, so I can't say if it works for other scenarios, too.

fletchgqc’s picture

I think you forgot to attach the patch.

Frank Steiner’s picture

FileSize
4.38 KB

Hmm, no I seem to have problems attaching files. Just saw that in another post, too. I upload and attach them but they just don't show :-( I'll try again.

Hah, ok, works now :-) Sorry for the delay!

rbishop’s picture

your attached "drupal_token.diff" patch is for the 2008-May-10 development release or for the official ?

Frank Steiner’s picture

It's against the 2008-May-10 development release.

alexknaub’s picture

FileSize
3.71 KB

The menupath-raw issue seems still to be there. Here is a patch against the 2008-jun-08 development release. It fixes for me all issues with menupath.

baronmunchowsen’s picture

Not sure whether this is a token issue with [menupath] or a pathauto issue, but posted it here because it replicates a problem documented above. If the mods feel that it's pathauto can it be moved across?

Installed:
Drupal Project (6.2 - 2008-Apr-09)
Pathauto Module (6.x-1.0 - 2008-Apr-30)
Token Module (6.x-1.x-dev - 2008-Jun-19)

Pathauto Settings (admin/build/path/pathauto):
Nodepath settings > Default path pattern: [menupath-raw]

Created content under 'Primary Links' and got the following menu structure and path aliases (also the pages were created in this order):

MENU                    URL ALIAS
--------------------------------------------
My Bike                 my-bike
 - Bike Wheels           my-bike/bike-wheels
 - My Bike Handlebars    my-bike/my-bike-handlebars
My Truck                my-bike/bike-wheels-0
 - My Truck Cab          my-bike/bike-wheels-1

See above - http://drupal.org/node/226074#comment-783188 - for similar experience.

Also, aliases were generated on page edit, not when created. I had to go back into the newly created node and resubmit the form to get url-aliases to generate. This seems to me to be more a pathauto issue.

Hope this is helpful. Happy to test patches if I know which ones to roll, against which releases.

ar-jan’s picture

Thanks for the patch (#27). I rolled this one against the 6.x-1.x-dev 2008-Jun-19 release without errors. It solves my menupath issue with Autopath.

kevinquillen’s picture

Another issue would be if you said this pattern:

[menupath-raw]/[title-raw].htm

But, don't assign the node into a menu item, it creates a .htm and you get an error page. Obviously, because you didn't assign it to a menu item- but it should be smart enough to fail gracefully.

greggles’s picture

@ghost25 - please define "fail gracefully".

@everyone_else - which patch do people agree is the best? Is it good enough to go in or does it need more work?

kevinquillen’s picture

Like, obviously as a developer I would know why that menupath pattern would fail- but there should be a small check within the function that happens if Automatic Alias is checked that would also see if Menu is defined for that node. I know its a little bit of a stretch, but for sites that have say a menu with sub menus, menupath is great for aliasing. But clients aren't always smart enough to add it into a menu.

greggles’s picture

@gh0st25 - I still don't understand what "fail gracefully" means. Let's try this:

1. Node path pattern is [menupath-raw]/[title-raw].htm
2. User submits a node without any menu entry and with the title "something"
3. Pathauto will alias it as example.com/something.html

Expected results:

3. Pathauto should alias it as example.com/foo

I need you to fill in "foo" in step 3.

Frank Steiner’s picture

About foo: Could pathauto warn the user via nodeapi/'validate' if the pattern contains menu parts and no menu entry was defined in the node edit form? The user could either define a menu entry or manually set an alias to get out of this.

About the patch: I'm only using token for pathauto, but for this the patch has been working flawlessly in the versions in posts #17, #24 and #27, so I vote for putting it into the CVS tree.

fletchgqc’s picture

May I take the opportunity to apologize Frank for not testing the patch you rolled as I said I would in #21. I got heavily involved in other work and also struggled to find a tool to apply patches under Windows!

ar-jan’s picture

Has the latest patch been committed to the jun-29 -dev, or is this still just a patch?

greggles’s picture

If something gets applied then we will update this issue and the status will change to "fixed".

The patch has obvious coding style issues (coder module will pick these out for you...). So, this patch won't be applied as is.

bforchhammer’s picture

Status: Needs review » Needs work

subscribing

Frank Steiner’s picture

FileSize
4.54 KB

Here's a new version against 6.x-1.x-dev (2008-Jun-29), re-adding the menu-link-title[-raw] tokens that got lost in alexknaubs version, and validated with the coder module.

alf nif’s picture

#39 thanks!! This patch works great!

greggles’s picture

I'm reviewing this now b/c I'd like to do a new 6.x release soon and like for this to be in it.

Can you clarify the need for "menu-link-title" ? Isn't that the same as "menu" ?

greggles’s picture

Status: Needs work » Needs review
FileSize
2.5 KB

Here is what I found in 5.x for comparison purposes:
1. Created a node where the menu item is called "some title" and it is in the primary links.
menupath: some title
menu: Primary links
2. Create a second node with the menu item called "another title" that is a child of "some title" created in step 1
menupath: some title/another title
menu: Primary links

So, I now see the motivation to add the new feature of "menu-link-title" which provides the last piece of the menupath (e.g. in my second step menu-link-title would be "another title").

One other thing I have noticed is that $node->menu is only available in the $node object when a node is being saved. If you get a node from node_load then you do not have that information. So...I'm working on getting the information in a different and somewhat more reliable method. The trade off of my method is that if the menu is in the process of being changed AND the module getting the tokens is getting it from some point before the menu module has saved the data then my method will show what the menu USED to be...

I'm more interested in getting the data consistently even when we aren't on a node insert than I am in getting it right before the node is inserted.

So, I've changed the patch around a little bit and left it so that the book tokens are still working (i.e. I removed the changes to _menu_titles()).

I also made sure that menupath is consistent with the 5.x behavior (which is to say that it returns all elements in the menupath including the current element).

Frank Steiner’s picture

After upgrading to the dev version from 2008-Jul-18 and applying this patch, I get
Fatal error: Call to undefined function dsm() in /usr/share/drupal/modules/token/token_node.inc on line 76
for every page I create. The page is there afterwards, but not even th user who created it can access it. So I guess sth. is wrong :-)

greggles’s picture

Good point. If you delete that line it should work fine (or use the attached...).

Frank Steiner’s picture

Hmm, I end up with
You are using the token [menu-link-title-raw] which is not valid within the scope of tokens where you are using it. now when I'm using it in the path for my pages, and indeed it doesn't show up in the list of valid replacement patterns, although it really is in token_node.inc and I even disabled and re-enabled pathauto and token :-(

greggles’s picture

Thanks for your continued bug testing/reviews Frank Steiner!

I've attached an updated patch which removes some pointless comments and needless newlines and then adds in the descriptions to the node_token_list which is what was making Pathauto confused.

Can you try one more time?

Frank Steiner’s picture

Seems to work fine!
Compared to the former patches it has changed in that menupath-raw includes menu-link-title now. Before, menupath-raw was missing it, so one had to use [menupath-raw]/[menu-link-title-raw] to get the full path. I guess that is indented? I'm not sure if there is a situation where having all but the last element of the menu path would make sense, so for me it is fine this way.
Thanks!

Frank Steiner’s picture

There is still a little issue with [menu-link-title-raw]: If that appears in the pattern, e.g. like [menupath-raw]/[menu-link-title-raw] and you create a page without a menu entry, pathauto will consider [menu-link-title-raw] (and only it, not [menupath-raw]) a string and not a pattern and create the alias "[menu-link-title-raw]" for the node.

greggles’s picture

re #47 - I made that change to be more in-line with the way that these tokens worked in Drupal5 (at least I think so).

re #48 - fixed in attached.

Thanks again for the reviews. I think we're finally getting there.

damjan.cvetan’s picture

Hello.

I've just patched the token_node.inc file with #49 patch and it looks just fine for me. Tnx

Frank Steiner’s picture

Looks fine!

greggles’s picture

Status: Needs review » Fixed

And committed to 6.x.

Thanks again Frank Steiner and everyone for your help with patches and reviews.

dascope’s picture

awesome, thank you!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Renee S’s picture

Hmm, I'm getting this problem with the most recent dev release. ??

DjC4’s picture

Version: 6.x-1.x-dev » 6.x-1.11
Status: Closed (fixed) » Reviewed & tested by the community

I'm still having this problem in D6.9 with the latest build of Token. Installed from Acquia.

Is anyone else? Am I doing something wrong?

DjC4’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Changed Status

Frank Steiner’s picture

It's only fixed in -dev, not in 1.11

DjC4’s picture

Ooops! My apologies. I will download the dev version and begin testing it.

Thanks for the heads up Frank, I missed that. It looked like it got committed, but I read it wrong.

Sorry, I'm new here :P:P

fletchgqc’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

I guess we'd better change the status back.

temp’s picture

Sory but i open this thread another time.
some problem of token module witch link of int_meta module, we try solve this in this thread http://drupal.org/node/391328
i try witch 6.x-1.x-dev - and no changes.

temp’s picture

Status: Closed (fixed) » Active
Renee S’s picture

I'm using the latest of each, both pathauto and token, and I'm still getting this problem. It doesn't work if the content is part of a book. I want my menu aliases to follow the menu and then the book... !

temp’s picture

yes, i'm too, i use latest token dev relise and http://drupal.org/project/int_meta, token for menu dont work.
stay witch problem from #61.

kevinquillen’s picture

Yes, I can confirm it does not work. It seems to get the menu trail but no title.

Example, using menupath-raw on a content type of Event

I place the new node in Events > Festival

When I save, pathauto creates an alias of events/festival.htm.

If I try again, I get events/festival.htm-0, and so on, and so forth.

kevinquillen’s picture

Is it because menu_get_all_data is getting ONLY nodes that are status = 1? We just notcied that when dealing with unpublished nodes.

PeteS’s picture

To clarify, what we're seeing is that, in the _menu_titles() function in token_node.inc, the code loops through data from the D6 function menu_tree_all_data(). But menu_tree_all_data() seems to filter out unpublished nodes no matter what (status = 1), which means that token can't see unpublished nodes for the purposes of menupath/menupath-raw. Sooo... am I mistaken, or should token_node.inc not be relying on a function that strips out unpublished nodes?

kevinquillen’s picture

Hello? Bueller?

greggles’s picture

Assigned: greggles » Unassigned
Status: Active » Closed (fixed)

This was the original issue on this topic. New issues about menu tokens not working in certain circumstances should be new issues.

Also, patches welcome.

benorgan’s picture

Status: Closed (fixed) » Active

#67 you are right, changing this in includes/menu.inc makes the token / pathauto work as expected but I don't really think changing core code is a valid solution.

Can this be reopened and fixed or is there a new active issue for this problem?

greggles’s picture

Status: Active » Closed (fixed)

This was the original issue on this topic. New issues about menu tokens not working in certain circumstances should be new issues.

benorgan’s picture