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
Comment #1
jojo86 commentedDoes anyone know how to answer this? I'm so stuck!
Comment #2
jojo86 commented*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!!!
Comment #3
modernaut commentedHi,
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
Comment #4
technikh commentedsubscribing..
Comment #5
robloachWith #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.
Comment #6
dave reidI 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.
Comment #7
manuel.adan