It would be convenient to have access to everything about the message in the theming world.
For example, I've been adding some custom fields to mail_edit's mail template forms to expose more 'regions' of the email that can be edited by the user (e.g. footer text, header text), but I need to access their values in the template to render them out.

It would be simple enough to add $message as an extra parameter to the theme call.

Comments

jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.69 KB

Patch attached

sgabe’s picture

Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Status: Needs review » Needs work

I think it's meaningless to add $message as an extra parameter, since it has everyting we need, we should remove all the other parameters and use just that.

There are some other functions e.g mimemail_prepare_message() where we should replace the existing parameters to $message but that will be another issue.

sgabe’s picture

Title: Pass $message to theme function/template » Use $message for themeing
Status: Needs work » Needs review
StatusFileSize
new5.52 KB

I am attaching an initial patch to use only $message for themeing.

jotha’s picture

StatusFileSize
new2.26 KB

The patch attached in #3 is no longer valid for current versions. I attach a simple patch that I am using in a high-traffic site, which only include $params variable present in drupal_mail function call.

sgabe’s picture

StatusFileSize
new7.31 KB

Here is a new patch against the current state of the development snapshot.

rooby’s picture

This is definitely needed to be able to theme specific emails properly.

Is this something that will likely be committed to 7.x-1.x at some stage?

If so there will have to be a notice to users regarding the change as it could break people's overridden templates.

This would be avoidable by not removing the variables:
- * - $recipient: The recipient of the message
- * - $module: The sending module
- * - $key: The message identifier

from the template.

In which case it would reduce the risk of breaking things but it would be a good idea to have a notice anyway.

The patch is a great improvement though.

rooby’s picture

I have tested the patch in #5 and it works as expected.

From a code point of view it looks good too.

sgabe’s picture

#2167937: Pass $params (or other fields from the original $message) to preprocess and the template file marked as a duplicate of this.

Patch in #5 still applies fine and needs review.

srdjan.marjanovic’s picture

I downloaded latest version of the module (version = "7.x-1.0-beta1+5-dev") and i have trouble applying patch. Does this patch still apply?

sgabe’s picture

Issue summary: View changes
StatusFileSize
new7.29 KB

Rerolled patch attached.

rooby’s picture

Any comments on #6 in terms of not removing the variables vs removing them and writing a change notice?

sgabe’s picture

@rooby, I think we should use only the $message variable for hook_theme() but would be a good idea to preserve $recipient, $module and $key variables in the template_preprocess() implementation.

rooby’s picture

Yeah I agree, thanks.

greggadsdon’s picture

StatusFileSize
new1018 bytes

For those who do want to take the approach from #1 but with the latest version of MimeMail, find a patch for that attached.

mpotter’s picture

Status: Needs review » Reviewed & tested by the community

I think #14 is super straight-forward and should be RTBC'd. This functionality is greatly needed and this issue is languishing.

We can debate whether to remove the existing variables (as in #10) separately. In fact, separating these approaches would be a good way to deprecate the old variables and give people time to update their existing hooks and template overrides.

Using patch #14 now in Open Atrium.

ptmkenny’s picture

I agree with #15. I was bashing my head against the wall trying to figure out how to get access to some variables when I should've just searched the issue queue to find this patch.

ultimike’s picture

I completely agree with mpotter and ptmkenny - this needs to be committed ASAP, it's necessary and useful functionality (and pretty amazing it isn't already part of MimeMail).

-mike

  • sgabe committed 6b6146b on 7.x-1.x authored by jamsilver
    Issue #1568680 by jamsilver: Use $message for themeing
    
sgabe’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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

sgabe’s picture