Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Since I don't have time to try and ajax enable the token tree, I'm going to try and alternate solution and encourage the token tree not to be output directly in page output, but rather encourage linking to 'View available tokens' which would open up a jquery UI dialog with the token tree inside of it.
Comment | File | Size | Author |
---|---|---|---|
#12 | 1684984-token-browser-dialog.patch | 5.11 KB | Dave Reid |
#3 | 1684984-token-browser-dialog.patch | 4.54 KB | Dave Reid |
#2 | 1684984-token-browser-dialog.patch | 4.25 KB | Dave Reid |
Comments
Comment #1
Dave ReidOh my gosh, I think I have this working. Will post patch shortly.
Screenshot:
http://i.imgur.com/FIYgR.png
Comment #2
Dave ReidComment #3
Dave ReidRevised patch that fixes the CSS inside the modal only.
Comment #4
DamienMcKennaIs the patch missing something? I don't see what generates the link? With the current -dev codebase of both Token and Metatag, and this patch applied, I'm still getting the Ye Olde table underneath the Metatag fields.
Comment #5
Dave ReidWe would have to change the implementing modules.
From:
'#theme' => 'token_tree'
To
'#theme' => 'token_tree_link'
That change is out of scope for this patch.
Comment #6
DamienMcKennaFor anyone else who wants to test it, you can e.g. change metatag.module line 629 per Dave's comment in #5, or any other module that uses 'token_tree' to display a list of tokens.
Ok, this works pretty well.
There's a UX glitch at play that either is a core bug or something unique to this (I'm not sure off-hand). To reproduce:
Related to the above, should the table header float if the dialog is scrolled through? Right now it isn't, only when the *page* is scrolled.
I also wonder might it be better to just replace theme_token_tree entirely (hook_theme_registry_alter() if need be), rather than require modules update to using a new dialog? Maybe provide a variable to control which one is used, so that by default when the Token module is enabled you get the new dialog but can disable it if you need?
Comment #7
Dave ReidI'm not sold on changing the default behavior of theme_token_tree() to output a link by default. I feel like that defeats the purpose of having the two separate theme functions. I can list off the top of my head the few modules that would need to get patched for this. Should we really force it by default?
Comment #8
Dave ReidI'd probably be ok with supporting 'dialog' => TRUE if added to theme_token_tree would return the output of theme_token_tree_link instead. This way modules could use the same '#theme' => 'token_tree' but with the newer version of Token it would output the dialog link instead.
Comment #9
DamienMcKennaI think providing the better UI by default should be the way to go, then provide an option to revert to the older format if necessary ("more better" by default).
Comment #10
Dave ReidAdding performance tag.
Comment #11
puddyglumSubscribing, this would really help us with #1694720: causes unresponsive script jquery warning
Comment #12
Dave ReidLatest version of the patch. I want to go with this version for now.
Comment #13
Dave ReidCommitted #12 to 7.x-1.x with http://drupalcode.org/project/token.git/commit/fb05b22
Comment #15
Alan D. CreditAttribution: Alan D. commentedNice. Big thanks. We can start removing the themed custom popups that we have been implementing on sites ourselves. It will be interesting to see how these differ.
Comment #16
DamienMcKennaFYI here's how I'm using it in the Field Redirection module:
Obviously adjust the form spec as necessary.
Comment #17
Dave ReidYou don't even need to do that. Just do the following and it works regardless of version, but uses the modal if the version supports it.
Comment #18
DamienMcKennaDaveReid++
Comment #19
Dave ReidCorrection: '#modal' in #17 should be '#dialog'
Comment #20
rudiedirkx CreditAttribution: rudiedirkx commentedI actually don't think this is right...
theme_token_tree_link()
takes arguments from the['#theme' => 'token_tree_link']
element to pass to the link. The link sends them to the page callback to render them usingtheme_token_tree()
. However, theme keytoken_tree_link
doesn't accept all the variables that can be passed to theme keytoken_tree
. For example:token_types
.If you can't pass it to
token_tree_link
, you can't pass it totoken_tree
. I've tried withoptions
, but I can't get it into the link's query.Maybe I'm wrong. Maybe I've been missing something for the last 20 mins =)
Comment #21
rudiedirkx CreditAttribution: rudiedirkx commentedForget it. I wasn't paying attention. I assumed you had to change the
#theme
key, but you have to add#dialog
.Comment #22
Sk8erPeter CreditAttribution: Sk8erPeter commentedShouldn't this issue be marked as "fixed" only if this feature can be enabled without modifying other modules which support Token integration? Or is it the task of the other issue, Token UI 2.0? I know I can also use Token tweaks module until then (btw., thanks for that, too), but I don't really see any updates on this topic since a while. Any plans on that?
Thanks for your efforts!
Comment #23
Dave ReidIt is up to other modules to use the new option, or for Token tweaks to provide an option to make everything use the dialog by default. There is nothing left to resolve in this issue and it is already closed as fixed.
Comment #24
DamienMcKennaLets continue the discussion in #1842738: Provide admin setting to replace all uses of the core token browser with the new popup.