Would be great to see a Drupal 7 version of this handy module.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | token_custom-7.x-1.x-dev.tar_.gz | 19 KB | gaspaio |
| #18 | token_custom-7.x-1.x-dev.tar_.gz | 19 KB | gaspaio |
| #13 | token_custom-7.x-1.x-dev.tar_.gz | 19 KB | gaspaio |
| #12 | token_custom-7.x-1.x-dev.tar_.gz | 18 KB | gaspaio |
Comments
Comment #1
hanoiiwill probably be working on this on Jan
Comment #2
W.M. commentedI will happily test and provide feedback.
Comment #3
mskicker commentedi think that is important for drupal 7 too and i try help you about test it
Comment #4
darkadept commentedI would love to test it as well. This module would help me very much!
Comment #5
gaspaio commentedhow's work on custom tokens D7 going ? When are you planning to do a first release ?
Comment #6
jeffwidman commentedsubscribe
Comment #7
Rix-1 commented+1 (please go for it! be a hero)
Comment #8
basicmagic.net commentedsubscribe
Comment #9
gaspaio commentedCould we have some feedback here ?
If you don't have the time to do it i'll gladly work on it ; just don't want to duplicate the effort.
Comment #10
hanoiiSorry for the silence. To be honest, I haven't really moved into heavy drupal 7 development.
If you want to contribute a working version of this module for D7 I will be more than fine to try it out, and commit/release it if it looks Ok.
Comment #11
gaspaio commentedThanks for the feedback.
I'll try to produce a quick port in the next few days, as a starting point.
Comment #12
gaspaio commentedAs promised here's a quick and quite untested port of token_custom to D7.
As most of the token api has been put in core, this version is no longer dependent on Token.
Appart from the expected bug hunting, typo correcting, etc, i'll be working on several other features :
for sitewide constant values (like specific nids, tids, etc.), plain text is more than enough for this.
Feedback is of course most welcome.
Comment #13
gaspaio commentedSame as #12 but drupal coding standards compliant.
Comment #14
W.M. commentedThanks very much gaspaio. I will look into this and try it.
Comment #15
W.M. commentedThe attachment file under #13 results in extraction error. The tar.gz file appears to be broken.
Comment #16
gaspaio commentedI just downloaded the file and extracted it.
Did you change the name to token_custom-7.x-1.x-dev.tar.gz ?
I'm using : tar (GNU tar) 1.23, on Ubuntu.
Comment #17
W.M. commented@gaspaio
It is fine now. I have managed to exract the archive. I have created two custom tokens to return:
a. the last two digits of a nid
b. 3rd and 4th digits of a nid
The codes are:
a:
b:
This worked fine on D6 and official release of Custom Tokens module. Yet in D7 the dev version posted above results in these errors:
Notice: Undefined variable: node in eval() (line 2 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 2 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Undefined variable: node in eval() (line 6 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 6 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Undefined variable: node in eval() (line 9 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 9 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Undefined variable: node in eval() (line 1 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 1 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Undefined variable: node in eval() (line 4 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 4 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Notice: Undefined variable: l00_01 in eval() (line 10 of /home/user/public_html/mysite/sites/all/modules/token_custom/token_custom.module(275) : eval()'d code).
Any ideas what might be wrong here ?! Maybe in D7 $node->nid should be written in another manner ?!
Comment #18
gaspaio commentedI see what it is.
There was a change in the token api from the D6 Token module and the D7 core tokens.
The D7 function token_replace receives as argument the $data array, containing any loaded objects : the $user, the $node, etc as $data['user'], $data['node'], etc.
This allows for more data to the available to the hook_token implementations.
Your code should then start with :
The type of your custom token should also be 'node', to avoid runtime errors. Drupal should not try to replace your token if the 'node' entry is not available in $data.
Here a new build, with a small correction : in the token list page, we don't try to print a demo value if the token needs external data (like a user object, a node, etc).
Comment #19
W.M. commentedI have tested your suggested modification to my code. It works as it should now.
Thanks for all the effort you put into this project.
Comment #20
hdcoder commentedPlease publish any simple example token_custom for use with path.
PS:
I create new token_custom:
- Token name: Test.
- Machine name: node-publ-term.
- Token description: Simple text.
- Token type: [needs:node].
- PHP replacement: return "test";
In path module in section for nodes set default template: [node:node-publ-term]/[node:nid]
Result: I have error save settings path module. [node:node-publ-term] not found.
Please help.
Comment #21
W.M. commentedMy response relates to the dev version found under relpy #18 by gaspaio.
The module works great, however I have noticed a strange problem that may be caused by faulty code at:
a, above mentioned D7 dev release of Custom Tokens
b. Token module
c. Filefield paths (latest stable)
The problem is that I get an invalid (not found) token error when specifiying the name of a custom written token in the filefied path of an image field in a RTL site. If I switch the main language to Englsih and put the same token name in the custom path field and submit the form, it works (no error reported and the setting is stored to teh database).
I have that we can work togother to make this module better.
Comment #22
gaspaio commented@hdcoder
I can't reproduce your issue. I installed pathauto RC2 and added a custom token using your instructions and set the path alias to [node:node-publ-term]/[node:nid].
When i create a new node, its path is "test/1", as expected.
Any ideas on what might be going wrong with your installation ?
Comment #23
gaspaio commented@Geir19
This will sound suspicious (cf. #22 :-D) but i'm having trouble reproducing your issue also. Here's what i did :
1) installed filefield_paths (latest stable) and token
2) defined a custom token of type node
3) used it in the path of an image field
4) downloaded and installed the arabic language
5) Set it as the default language
6) blindly navigated to the add content section and added an article with an image.
I got no error messages, the file was saved in the correct directory using the custom token i defined.
Any ideas ?
Comment #24
gaspaio commentedJust thought of something : my keyboard is a french one, and the path and token were writen in a LTR language and latin alphabet. Perhaps the error doesn't comme up unless the token of path is typed in a RTL keyboard.
Does filefield_path perform well with normal tokens in a RTL context ?
Comment #25
hdcoder commentedgaspaio thank you! I had an older version pathauto (7.x-1.0-beta1). Updated and it worked!
Comment #26
W.M. commentedI think the Drupal 7 version provided by gaspaio should be made public (available at main module page). It simply works. Thanks a lot gaspaio :)
Comment #27
gaspaio commentedThanks Geir19.
I actually would like to maintaint the D7 port and add some features (like features support) to it.
@hanoii : is it possible to add me as a co-maintainer for this module ?
If no release is done in a few weeks, i'll probably end up creating a new project for the D7 version, although its a shame to multiply related projects.
Comment #28
W.M. commented@gaspaio
I want to inform you that the latest release of Token (version 7.x-1.0-beta4) conflicts with token_custom module for Drupal 7 (that you have provided earlier at this post).
Upon editing previously created nodes or creating new ones, I get these errors:
The php codes I use to generate numbers based on nid did not change at all. The thing that resulted in all those errors is upgrade to Token (version 7.x-1.0-beta4).
In the image path, the directory name which should have the value provided by custom_tokens is "Array".
Comment #29
W.M. commented@gaspaio
I have used the same PHP codes above inside a custom module of my own and hooked into hook_tokens and hook_token_info.
It works fine with no problems or conflicts. The custom module I have created works perfectly with the latest Token module (version 7.x-1.0-beta4).
I will happily see the original Custom Tokens module working flawlessly inside Drupal 7. I love the UI. Makes token management and authoring easier.
Thanks for the help so far, I have learned much from reading the code. Best wishes.
Comment #30
gaspaio commentedI gess there's something wrong with the eval function call on the custom token's php code.
Anyway, i'm thinking of using the core's php filter to evaluate custom tokens instead of the eval function, it seems much more like the 'drupal way' to do it.
I'll try to check it out over the weekend.
Comment #31
gaspaio commentedIndeed there's some weird stuff going on here. It seems that the token module is trying to evaluate tokens of type 'node' without filling the $data['node'] entry, instead it does $data['entity'] and $data['entity-type'].
There's another problem though, even when i evaluate simple text with a custom token i get errors from pathauto ; different ones but errors still.
This is more complicated than i though ; i'll have to give it another go soon.
@Geir19 : if you have any idea of how to correct this ...
Comment #32
dave reidI'm confused by "It seems that the token module is trying to evaluate tokens of type 'node' without filling the $data['node'] entry, instead it does $data['entity'] and $data['entity-type']."
Comment #33
gaspaio commented@DaveReid : and you have all the right to be confused because I was wrong, it's not the token module nor anybody else, there was a bug i my code. Sorry about that :-).
Here's an updated version that should work with @geir_19 test cases and correct the notices in #28.
Comment #34
W.M. commentedThanks gaspaio for the great work. It works perfectly now :) New version of Sep. 3rd 2011, passed my tests.
Comment #35
gaspaio commentedI'm thinking of starting a new project with my D7 port. I haven't been able to context custom token's maintainer via DM.
What do you think ?
Since the machine name for custom tokens is actually token_custom, i could call my module custom_tokens.
I do think this is not the way to proceed, but i don't see any alternative. Any ideas ?
Comment #36
hanoiiHi @gaspaio, Sorry, I am a bit busy but I generally answer DM always. It must have slipped when I read it. not necessary to add another project. So, are you up to adding and maintaining the D7 port? Will try to give a quick review to the code, but otherwise, I don't mind co-maintainship
Comment #37
hanoii@gaspaio, just granted commit access. Leave you to fix this issue when necessary.
Comment #38
gaspaio commentedThanks @hanoii.
Just commited the #33 version to the newly created 7.x-1.x branch.
Thanks to @geir19 for the precious feedback.
Comment #39
leanderl commentedHi, I used this module for D6 and would love to help if I can with the D7 version.
Right now I've installed it and I only get the "white screen of death" after having tried to create a token. Has anyone encountered this? As far as I can see from the code, things related to the module should be stored in db table token_custom. So I wanted to clear that table "by hand", but it isn't there (hasn't been created). Hence it is weird that I have a white screen of death for "admin/structure/token-custom/list" when there isn't even any data. Hmm...
Comment #40
leanderl commentedIt turns out it was my PHP/SQL that was out of order.
This was the D6 way of getting your token
This is the D7 syntax for the same thing
Again: great work gaspaio!
Comment #41
justmagicmaria commentedI'm using the version from #33 with the world's simplest PHP for my custom token: return "Test";
The token type is Node.
When I use the token (in the configuration of the Talk module to set the value for the Talk tab) I get:
Notice: Array to string conversion in str_replace() (line 97 of /
/includes/token.inc).
and the value that gets printed is "Array".
I'm using 7.x-1.0-beta6 of Token module.
Any ideas?
Comment #42
hdcoder commentedThanks for fix #33!
Comment #44
jordanmagnuson commentedCan we please get an official 7.x dev release? Still no 7.x branch on the module page.
Comment #45
gaspaio commentedActually i'm trying to do a release but there is a bug in Drupal.org that prevents my tag from appearing in the possible releases select. According to the support mailing list it should be easy to fix for a drupal.org administrator, but none has picked up the issue i opened so far.
I'll probably just create another tag one of these days and see if it works.
I'm releasing a beta version directly. Since the module is pretty straightforward, i don't see the need for a dev release right now.
Comment #46
gaspaio commentedRelease 7.x-1.0-beta2 is out and should be available in a few hours.
If no important bug is reported in the next week or two i'll roll a official 7.x-1.0 release.
Comment #47
dtj commentedI seem to be having a difficult time using more than one custom node token.
I can create one node token and it appears under "REPLACEMENT PATTERNS" but the second node token I create does not appear under "REPLACEMENT PATTERNS".
Comment #48
gaspaio commentedIndeed. The token module adds a cache table for token information. New tokens don't seem to be available without clearing the caches.
I just commited a token_clear_cache() after every custom token save and delete.
Can you empty the cache manually and see if it solves your problem ? After that, can you download the latest version of token_custom from the git repo and test it ? it should work.
Thanks for the bug report.
Comment #49
gaspaio commentedI am closing this issue since the release is out and we can now open new 7.x issues.