If in your rules settings you use a token that replaces into text that contains tokens, the second replacements don't work.

For example, if I have a rule that send a node body text in an email and that node body text has tokens in it, they don't replace.

To reproduce:

  • Add this rule to send an email when a basic page is created (change the email address if you aren't redirecting emails to yourself already):
    { "mimemail_rules_token_replacement" : {
        "LABEL" : "Mimemail rules token replacement",
        "PLUGIN" : "reaction rule",
        "OWNER" : "rules",
        "REQUIRES" : [ "rules", "mimemail" ],
        "ON" : { "node_insert--basic_page" : { "bundle" : "basic_page" } },
        "DO" : [
          { "mimemail" : {
              "key" : "node-save-notification",
              "to" : "myemail@example.com",
              "from_mail" : [ "site:mail" ],
              "subject" : "New node at [site:name]",
              "body" : "A new page titled [node:title] has been created by [node:author:name]. It\u0027s content is:\r\n\r\n[node:body]",
              "plaintext" : [ "" ],
              "language" : [ "" ]
            }
          }
        ]
      }
    }
    
  • Add a node that contains node tokens. Note that site tokens will still work because they don't rely on the object coming in through rules. Here is an example:
    This content has tokens:
    [site:name]
    [node:title]
    
  • When the email comes though the node tokens from the body will not be there and will not have been replaced. If using my example body, the second token won't work.

Looking at the code in mimemail_mail(), it is passing $context into token_replace() as the $data.

I haven't looked in any detail into other, non-rules cases, however with these rules emails that is definitely not what should be getting passed in that parameter. I would assume that non-rules cases still shouldn't be using that variable in that way.

The rules action actually does pass in the required data but it is further down in the $context array.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rooby created an issue. See original summary.

rooby’s picture

Here is the first cut of my fix for this.

It gets the objects that were passed in from rules and uses those for token replacements.

If it is not from rules it will only token replace based on global tokens (others never worked anyway).

The other case I need to handle is the mimemail_action module action. I need to add support for passing it's token related object through.