Hi,

I've attached a patch which allows the Token module to be used for substitution in reminder, confirmation, and broadcast emails. It doesn't remove the existing placeholders so as to not break existing sites. If the token module does not exist, then nothing is changed.

A few thoughts I had about the current implementation:

  1. The token module doesn't provide a themed version of available tokens. It's up to each module to do that on it's own. I've adapted code from Pathauto, which is definition list based, but I wonder if ecommerce's table view is better.
  2. There's a little bit of code duplication all ready in terms of token replacement. For reminder/confirmation/broadcast emails, would it be better if they called a function to do replacement instead of doing it on their own?

The patch is against -dev, but it applies cleanly with a fuzz of 7 to the 2.4 release. Please let me know if there are any questions or comments.

Thanks,
--Andrew

Comments

dww’s picture

Status: Needs review » Needs work

Cool, thanks for getting this started -- seems like a good thing overall. A few problems I spotted from a very quick skim of the patch:

A) $tokens[t('['. $pattern .']')] = t($description);
That's now how t() works. You can't t() a variable, only string literals.

B) "avaialable" is misspelled.

C) I don't like having the duplicate code to get the token help text HTML. At the very least, that could be generated in a private helper function and shared. It's kinda silly that token doesn't provide this itself, to be honest.

I'll look more closely when you post a patch that fixes these and I have time to actually test it.

Thanks again!
-Derek

deviantintegral’s picture

StatusFileSize
new5.4 KB

I've removed translation for now, since as I understand it's a no-op. I got that line from pathauto, so I'll check it out with them. Fixed the typos, and move token help generation into a private function which calls a theme function for the HTML rendering.

I also removed the != 'global' check, since it's entirely reasonable to want to include [site-url] and the like in an email.

--Andrew

deviantintegral’s picture

Status: Needs work » Needs review
dww’s picture

StatusFileSize
new7.15 KB

I gave this a close review and some testing. I found some problems, all of which I've fixed with this patch. Please test it out and see what you think. For the record, here's what I did:

A) Token.module expects tokens in your message to be wrapped in [], such as [nid], so the help text needs to show that.

B) Even with the private method to create the help text HTML, the previous patch was still duplicating a fair bit of code to create the fieldsets. So, I added _signup_token_help() which takes a $form array by reference and a form element name (for the fieldset) as args, and adds the fieldset and help text.

C) I made _signup_build_token_help() statically cache its results in cases where it's called twice on the same page load.

D) The way you were just conditionally appending "Additional tokens provided by the token module are available for substitution." would make it impossible to translate this module into an RTL language. So, I reworked that stuff in a way that I think will still be RTL-friendly. It's a wee bit unwieldy, but I think it's the best we can do. ;) I also think it's nicer not to mention "token.module" in user facing text like this, so I think the end result is cleaner for users.

E) The call to token_replace() was wrong for the confirmation emails, since you were passing in $event->nid even though $event didn't exist. In fact, we've already got a fully loaded $node object in that case, so we just use that instead of calling node_load() again (even though it's cached, it's still wasteful).

F) Ditto the token_replace() call for the signup_broadcast thing -- we've already got a fully loaded node in $event, so we use that directly.

This is going to be very slick, and will solve lots of problems, such as #117203: Adding CCK fields to reminder email, so I can't wait to get this in.

Thanks!
-Derek

dww’s picture

Priority: Normal » Critical

Note: until token.module provides a token for the URL of a node (see #127613-6: Provide tokens for node url and path (i.e. absolute and relative alias respectively)) we'll need that ourselves: #265222-3: Event URL in email with %eventurl string.

I'd really like to get this in ASAP, so I'm bumping the prio...

duellj’s picture

Status: Needs review » Reviewed & tested by the community

Tested with and without token module enabled. Works great!

dww’s picture

Status: Reviewed & tested by the community » Fixed

Great, committed to HEAD. Thanks, everyone. Yay.

lut4rp’s picture

Status: Fixed » Closed (fixed)

Oh, I was late :-( But, it works fine here anyway :-D

dww’s picture

Status: Closed (fixed) » Fixed

Actually, let's leave this as just "fixed" for now, so it's still visible in the signup issue queue for others who are looking. It'll get automatically closed in 2 weeks. But thanks for the other testing.

deviantintegral’s picture

Thanks Derek for the improvements, everything seems to be working for me as well.

--Andrew

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.