Hi

I want to be able to create a custom token that is based on existing tokens.

Basically, I want to be able to specify my custom token in the URL alias for pathauto that will create a URL alias for each content item that I add. I was originally using [menupath-raw] which would add the current menu structure URL to the alias for that content item - e.g. Item 1 > Article 1 would have the URL of item-1/article-1.

This was working great until I tried to add some content that is not going to be added to the menu system and thus when I added a piece of content, the URL alias was node/nid (nid being replaced with a number obviously). I know that each piece of content should be added under a menu item for ease of navigation but this project is not for myself and I can't guarantee that everyone who uses it will remember to add the content items under a specific menu.

What I would like to do to say something like:

if (!empty($tokens['menupath-raw'])) {
$tokens['token_custom_url'] = $tokens['menupath-raw'];
}else{
$tokens['token_custom_url'] = $tokens['title-raw'];
}

However this is my first time of creating any custom token so I don't even know where to start!!! I am presuming that the above is utterly wrong and really don't mind someone pointing that out straight away!

I would really love some help from you guys - if this has been asked and answered before, please tell me :)

Comments

jojo86’s picture

Does anyone know how to answer this? I'm so stuck!

jojo86’s picture

*BUMP* come on, someone must know how to do this, or at least point me in the right direction - I can't be the only one who would have wanted this function! Please help!!!

modernaut’s picture

Hi,

I shared your frustration.

I created a patch to the Token module which adds a new token, ['menupath-parents-raw'], which gives you the behavior you're looking for when you place the following into your automated alias settings:

[menupath-parents-raw]/[title-raw]

See my response here:
http://drupal.org/node/519834

technikh’s picture

subscribing..

robloach’s picture

With #1336622: Use Filters for Custom Tokens rather than PHP, and Token Filter installed, you can make a token based on other tokens. I don't have plans to backport that to Drupal 6 though.

dave reid’s picture

I don't think that would actually work though. Using a token filter inside a custom token filter text would lack object context and only global tokens would be able to be used.

manuel.adan’s picture

Status: Active » Closed (outdated)