Spinning this off from the core issue so I can have other people follow and review the code.
$build['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node', 'comment'), // Specific token types to include.
'#global_types' => FALSE, // Whether or not to include global token types like current-user, date, etc.
'#click_insert' => TRUE, // Make tokens clickable & insert into last focused textfield
'#recursion_limit' => 2, // Since tokens like comment and taxonomy terms can recurse infinitely, we have to set some kind of limit.
Improvements, comments, etc are completely welcome.
I've also uploaded this latest version to http://www.davereid.net/d7/examples/token
I've been in contact with the jQuery treeTable author as noted in the other issue and he's up for dual-licensing. I've made an official issue for the plugin at http://plugins.jquery.com/node/13634.
As far as usability, tokens stink in D7 without something like this. Completely unusable. Heretical as it is, it may be worth adding this feature to D7. Of course, those "in the know" will be able to use this from contrib.
Dave, one note is that D7 no longer has 'global' tokens. Every single token exists in a specific domain, even things like the current site name and slogan. So if someone wants the equivalent of the existing 'global' tokens, they would need to add 'current-date' and 'current-user' and 'site' to the list of token types to retrieve.
Also, to clarify -- I haven't had a chance to look too closely yet, but does the recursion limit affect all chaining? There are a lot of pretty useful tokens like [node:author:created:short] that would run into a 2-deep nesting limit.
Taking a look at the code now. Thanks!
I'd actually say that 'current-user', 'date' and 'site' are global tokens since they do not need data and will always work. The #global_tokens is just a TRUE/FALSE to include all possible global token types. User can easily put a FALSE value for that and manually specify the exact token values to be included in the tree.
The recusion limit is defaulted to 4 levels in the path. 2 was just a bad example, but it's over-ridable.
#7 +1 for #global_tokens the way you say (the same I thought when first saw it)
OTOH I would recommend a minimum of 5 level as a reasonable depth [comment:node:author:created:short]
@arhak: Technically the first part of the token doesn't count towards the recursion limit since it is only a type, and isn't a token that has chains, so that token is possible with a 4-depth limit. :)
@#8 thanks for clarification, then I'm ok with 4 (unless another token chain in core would be longer)
Dave, just to clarify -- is the reason for the depth limit because the entire tree gets pre-rendered? I've been kicking around the idea of an XML or JSON chunk describing all the token types and their relationships to each other (via the 'type' property) just being passed to the client side, and building the tree there to avoid the overhead. Would that be brutal, do you think?
Yes its because the browser I worked up does it all ahead of time. There were other jQuery table/tree type plugins that supported fetching rows via AJAX and the idea was definitely intriguing. Most of the code I wrote should be able to be re-used for that approach. I'm also working on token auto-completion in Token.module as well.
Makes sense. Eventually it would be cool to move to that sort of approach, but what you've posted above is also enough of a black box that the public interface to it wouldn't need to change if that approach were used down the line... I'd actually be thumbs-up on committing it to the D7 token branch as is, and treating it as something experimental. Token module in D7 could also form-alter the helper information into the spots in core that use tokens but don't fully explain them...
Hi, I'm Ludo van den Boom, the author of the jQuery treeTable plugin. Wanted to let you know that, as of release 2.3.0, the treeTable plugin is now dual-licensed MIT/GPLv2.
@cubicphuse: Woo-hoo! Welcome to the Drupal community and YOU ROCK!
I'll commit the current implementation to token D7 now.
Note that it must be GPLV2 and later to be included in Drupal's cvs repository.
Committed the token UI browser to CVS!
Marking this issue as fixed since its been committed to 7.x and 6.x.
Automatically closed -- issue fixed for 2 weeks with no activity.
Drupal is a registered trademark of Dries Buytaert.