Project:Mail Editor
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I wish to add a token !logo to the subscriptions.module mail template. I looked at mail_edit_user.inc which seems to indicate that I use mail_edit hooks:

<?php
//hook_mail_edit_tokens_list($mailkey, $options = array())
function lesspaper_mail_edit_tokens_list($mailkey, $options = array()) {
 
$tokens = array();
  switch (
$mailkey) {
    case
'default':
     
$tokens['!logo'] = "Site logo";
      break;
  }
  if (isset(
$options['tokens'])) {
   
$tokens += $options['tokens'];
  }

 
$tokens += module_invoke_all('subscriptions_tokens_list', $mailkey, array('tokens' => $tokens));

  return
$tokens;
}

//hook_mail_edit_tokens_value($mailkey, $object, $options = array())
function lesspaper_mail_edit_tokens_value($mailkey, $mail, $options = array()) {
  global
$base_url;
 
$account = $mail['params']['account'];
 
$language = $mail['language'];
 
$current_theme = variable_get('theme_default','none');
 
$settings = theme_get_settings($current_theme);
 
$logo_path = $settings['logo_path'];
 
$tokens = array(
   
'!logo' => '<img src="' . $logo_path . '" />',
  );
  return
$tokens;
}
?>

But, I'm not seeing the !logo token anywhere. I believe this is because the hooks only apply to the module from which they are called. However, it seems like there should be a way to do this.

I can't seem to find any documentation on how this is done. Could someone please help me? Thanks!

Comments

#1

Status:active» needs work

See function _mail_edit_include() inside mail_edit.module

#2

Thank you for your fast response. It would seem from what you are saying that I would need to:

1. Save my code above as a .inc file.
2. Modify the mail_edit.module code:

/**
* Include all Pathauto include files.
*/
function _mail_edit_include() {
  $pathauto_path = drupal_get_path('module', 'mail_edit');
  require_once("$pathauto_path/mail_edit_user.inc");
  if (module_exists('logintoboggan')) {
    require_once("$pathauto_path/mail_edit_logintoboggan.inc");
  }
}

to add a path to my inc file.

Is this correct? If so, is there a way to get the !logo token onto the subscriptions digest mail template without modifying mail_edit code directly?

#3

i dont remember anymore,i wrote this very long time ago. you should certainly give your steps above a try and report back your results. try something else if above doesn't work.

#4

Status:needs work» needs review

Because the hook calls to hook_mail_edit_tokens_list() and hook_mail_edit_tokens_value() seem to be tied to the module that provides the email (only user.module gets the hook call for emails generated by user.module) I couldn't find any way to add my own tokens to those already provided in mail_edit_user.inc.

It seems that there was some kind of support for adding your own tokens to those mails using drupal_alter, however it seemed to be only possible to add your own token keys, and not the actual values.

With the attached patch, I have been able to add my own tokens (keys and values) to existing user mails like so:

<?php
/**
* Implementation of hook_drupal_alter().
*/
function example_module_user_password_reset_alter(&$tokens, $op, $data = NULL) {
  switch (
$op) {
    case
'token_list':
     
$tokens['!faster_dsn'] = t("User's DSN number");
      break;

    case
'token_values':
      if (
$account = $data['params']['account']) {
        if (!empty(
$account->civicrm['external_identifier'])) {
         
$tokens['!faster_dsn'] = $account->civicrm['external_identifier'];
        }
      }
      break;
  }
}
?>

Here I am adding the token faster_dsn to the password_reset email provided by user.module.

AttachmentSize
mail_edit-alter-tokens.patch 1.06 KB

#5

Status:needs review» active

The original post was about adding tokens to the Subscriptions templates.

Subscriptions does not use mail_edit's token processing, because mail_edit does not support conditionals.

To add tokens to the Subscriptions templates, there's hook_subscriptions_token_list() and hook_subscriptions_get_mailvars().

For the general case, mail_edit_user.inc shows how to add tokens to mail_edit's token mechanism.

I'm not sure how to deal with this issue. #4 may be useful in some cases, but it has nothing to do with the original post...

#6

#4 turns out to be a very useful solution. Thank you, mrfelton, for the post and patch.

#7

#4 is an awesome patch! Just one thing to note if you have content profile, and certain fields are completed on the registration form that you want to use in the eMail, you'll have to get them from the $_POST array, as the content profile bits aren't saved yet.

Shawn

nobody click here