Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I needed token support for this module.
Simple patch:
wysiwyg_template.module: line: 244
'body' => module_exists('token') ? token_replace($dbTemplate->body) : $dbTemplate->body,
To show available tokens when editing template:
wysiwyg_template.admin.inc: line: 86
if (module_exists('token')) {
$form['token_help'] = array(
'#value' => theme('token_tree', array('global' => NULL)),
);
}
Hopefully this can be added to the module?
Comment | File | Size | Author |
---|---|---|---|
#7 | wysiwyg_template_token.patch | 959 bytes | tlaurent |
Comments
Comment #1
guybedford CreditAttribution: guybedford commentedThanks for the suggestion, and sharing your code.
Can I just ask - what was your use case for the token module here?
Comment #2
sauce71 CreditAttribution: sauce71 commentedThis is for an Ubercart site. I use wysiwyg in the order comments, and templates to insert text notifying the customer that they order is shipped etc. They like to use a variation of messages, and I use tokens to insert the name of the user handling / shipping the order.
Comment #3
guybedford CreditAttribution: guybedford commentedThanks - it's great to hear how the module is being used for thinking about future features!
I've committed the update for the next release.
Comment #4
sauce71 CreditAttribution: sauce71 commentedThanks :)
Next challenge will be to add some more context for Tokens. The order customers name comes to mind.
Not an easy generic solution for this, will probably add some custom tokens sniffing current order from a session variable.
Comment #5
tlaurent CreditAttribution: tlaurent commentedThis is indeed a very useful functionality, thanks for that.
One remark I have is that if I modify wysiwyg_template.module: line: 244 as recommended by sauce71, the tokens are not translated.
On the other hand, if I modify wysiwyg_template.module: line: 212 (wysiwyg_template_html_load function) instead, then it works:
return module_exists('token') ? token_replace($template['body']) : $template['body'];
I wonder why that is ?
I'm using wysiwyg_template 6.x-2.1-beta1 with token 6.x-1.15.
Comment #6
guybedford CreditAttribution: guybedford commentedYou're right about the above correction - tokens should be replaced when loading the template from the database, not at the point of saving. (Just like input formats are applied in Drupal).
Comment #7
tlaurent CreditAttribution: tlaurent commentedI generated a 2 lines patch for 6.x-2.2-beta1 users who would like to get the changes I mentioned above (tokens being replaced when loading the template from the database and not at the point of saving).
Comment #8
guybedford CreditAttribution: guybedford commentedThis has now been added in the 6.x-2.3 release.