Posted by Dave Reid on March 10, 2010 at 3:38pm
9 followers
| Project: | Token |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Dave Reid |
| Status: | closed (fixed) |
Issue Summary
Spinning this off from the core issue so I can have other people follow and review the code.
Comments
#1
Summary:
<?php$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.
);
?>
Todos:
Improvements, comments, etc are completely welcome.
#2
I've also uploaded this latest version to http://www.davereid.net/d7/examples/token
#3
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.
#4
Subscribing.
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.
#5
sub
#6
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!
#7
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.
#8
#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]
#9
@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. :)
#10
@#8 thanks for clarification, then I'm ok with 4 (unless another token chain in core would be longer)
#11
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?
#12
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.
#13
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...
#14
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.
#15
@cubicphuse: Woo-hoo! Welcome to the Drupal community and YOU ROCK!
#16
I'll commit the current implementation to token D7 now.
#17
Note that it must be GPLV2 and later to be included in Drupal's cvs repository.
#18
Committed the token UI browser to CVS!
#19
Marking this issue as fixed since its been committed to 7.x and 6.x.
#20
Automatically closed -- issue fixed for 2 weeks with no activity.