Hi
I have the need, for a menu_token replacement, that gets replaced if the node contains a specific field. If current page (this menu entry will be show on all pages) does not have a node or the node does not have the field, the token needs to be removed. Example:
menu token url:
resources/[node:field-my-specific-term:tid]
If field present replaced to:
resources/14
If field not present replaced to:
resources/%5Bnode%3Afield-my-specific-term%3Atid%5D
In the last case I would like to have it replaced to
resources/
There is an option that can be passed to token_replace called "clear". I have written a patch that adds a checkbox to the menu admin page and then utilizes the clear option on token_replace.
Please review and tell me what you think.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Screen Shot 2012-03-12 at 2.57.05 PM.png | 26.28 KB | rypit |
| #1 | clear_token-1471730-1.patch | 5.87 KB | bitkid |
Comments
Comment #1
bitkid commentedThe patch
Comment #2
bitkid commentedOh, by the way... I did a few other changes to the code, to have it comply with the Drupal Coding Standard. There was no actual changes to code, only to comments and empty lines.
Comment #3
rypit commentedIt looks like this was added to the dev branch on the repo - seems to work great.
Comment #4
dealancer commented@bitkid, thanks a lot for a patch! Looks like it was committed by Fubhy.
Also I have added lines:
To make sure user/[user:uid] is replaced to user, but not user/.
Comment #5
bitkid commentedThanks for adding my patch.
You are absolutely right about the trailing slash.
If someone decides on a better text for the checkbox, please feel free to update it :-)
Comment #7
rohittiwari commentedHi @dealancer,
Adding line
has resulted in truncating the trailing slash for link having menu token. So now,
https://[custom-tokens:example-domain]/arg1/arg2/ becomes https://[custom-tokens:example-domain]/arg1/arg2
I am looking into this. Requesting u to please if look into this.
Thanks,
Rohit Tiwari
Comment #8
rohittiwari commentedHi I figured it out,
There are basically two things you have to do to override
1. Increase your module weight to be greater then Menu token module
2. And remove the above code
to use the same.
For step 1 use in .install file
Then 2 step in your .module file
Thanks,
Rohit Tiwari
Drupal is awsome.