I created an advanced action "display message to user" with %title and then applied to workflow state change. The message simply shows %title rather than the actual node title. I'm not sure if this is an issue for Actions or Triggerunlock...

CommentFileSizeAuthor
#30 workflow-tokens.patch898 bytessharplesa

Comments

hillaryneaf’s picture

I found that the other variables do not work either for advanced actions with workflow state changes as well... I created an advanced action "send email" and found only %site_name works, the following do not:

%node_type
%title
%node_url

Does anyone else have this problem?

dirtabulous’s picture

I'm running into the issue when trying to send mail using actions. Did you ever get this figured out?

hillaryneaf’s picture

Nope, still find any solutions... I just used generic terms instead of the tokens

hillaryneaf’s picture

I haven't tried it yet.. but maybe this will help? http://drupal.org/node/195773

oriol_e9g’s picture

Component: Miscellaneous » Code

I have the same problem: I have tested the same functionality without the workflow module and works fine, but when I enable the workflow module and configure some actions message actions or email actions appear the string %node_url, %node_type, %title %body instead of the variable content.

oriol_e9g’s picture

Project: Triggerunlock » Workflow
Version: 6.x-1.0 » 6.x-1.0-rc1

I have changed the project because the workflow module include the triggerunlock functionalities.

danieldennis’s picture

Is this going to be addressed. It seems that sending email is a popular use of workflow.

jvandyk’s picture

Version: 6.x-1.0-rc1 » 6.x-1.x-dev

This is actually a bug in Drupal 6 core trigger module. We should roll a patch for D7 and have it applied to D6 as well.

It was fixed in Drupal 5 actions module (this commit).

hillaryneaf’s picture

Should this be moved to the D7 queue? or D6 queue?

attheshow’s picture

I'm having the same issue. I'm unable to send useful emails because of it. Does anyone have a patch for this?

kcpau’s picture

I have the same problem. Are you saying that triggerunlock will fix it??

hillaryneaf’s picture

No, jvandyk is saying it is a bug in the Drupal 6 core that would need to be addressed.

mullman’s picture

How do I apply the fix from #8 in my Drupal 6 installation?

adaven’s picture

subscribing

mattmackay’s picture

Are we able to successfully use variables when sending out emails from workflow (as that is a pretty significant chunk of my use case my workflow and drupal)?

Or are we saying that we need to wait for Drupal 7 before it works??

Thanks

adaven’s picture

I've just submitted a patch for D6 that should fix this issue #339770: system_send_email_action doesn't check context for node. It's pretty much the same as the patch referred to by jvandyk in #8!

meba’s picture

adaven’s picture

lol! beaten to it by a day - nice work though.

oriol_e9g’s picture

Status: Active » Fixed
scottrigby’s picture

Proposed core patch at link #19 works for D6. It's a shame to have to do this, but sending emails with workflow is kind of important :)
But the more people who test this (probably test in D7 as well) the more likely it will get into the next release of D6.

Status: Fixed » Closed (fixed)

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

ernesto.allely’s picture

I tried apply the patch described in #339591 with some changes to workflow module and apparently it runs. (at the end of workflow.module)

/**
* Implementation of hook_mail()
*/
function workflow_mail_alter($message){
  if ($message['params']['context']['hook'] == 'workflow'){
  $params = $message['params'];
  $context = $params['context'];
    if (isset($context['node'])){
    $node = $context['node'];
    // Esta función se utiliza para obtener el estado del workflow (variable %status)
    $status = workflow_get_state($node->workflow);
    $variables = array(
        '%uid' => $node->uid,
        '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
        '%node_type' => node_get_types('name', $node),
        '%title' => $node->title,
        '%teaser' => $node->teaser,
        '%body' => $node->body,
    '%status' => $status['state'],
      );
    }
    $subject = strtr($message['subject'], $variables);
    $body = strtr($message['body'][0], $variables);
    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
    $message['body'][0] = drupal_html_to_text($body);
  }
}

What do you think?

Bob Stein’s picture

Here is a more complete fix for workflow.module. It can be cut and pasted onto the end of workflow.module and works without having to make any changes to core.

What follows is mostly Ernesto's work, but includes a few lines (from user arnoldc) that make sure %author calls the right information if %author is present in the email action Recipient field rather than a specific email address. More information about this is at http://drupal.org/node/339591

/**
* Implementation of hook_mail()
*/
function workflow_mail_alter($message){
  if ($message['params']['context']['hook'] == 'workflow'){
  $params = $message['params'];
  $context = $params['context'];

  if (isset($context['node'])){
    $node = $context['node'];
    $author_account = user_load(array('uid' => $node->uid));
    // This function is used to obtain the workflow status (%status variable)
    $status = workflow_get_state($node->workflow);
    $variables = array(
        '%uid' => $node->uid,
        '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
        '%node_type' => node_get_types('name', $node),
        '%title' => $node->title,
        '%teaser' => $node->teaser,
        '%body' => $node->body,
    '%status' => $status['state'],
      );
     
      if ($message['to'] == '%author') {
      $message['to'] = $author_account->mail;
      }
    }
  
    $subject = strtr($message['subject'], $variables);
    $body = strtr($message['body'][0], $variables);
    $message['subject'] = str_replace(array("\r", "\n"), '', $subject);
    $message['body'][0] = drupal_html_to_text($body);
  }
} 
attheshow’s picture

Status: Closed (fixed) » Reviewed & tested by the community

Patch #23 works really well for me. Great contribution ProfStein! No hacking core. :)

speis’s picture

this works great, the only thing is, it doesn't honor any html tags like
or

which kinda screws up my email format message.

Can this be fixed?

smacphail’s picture

The HTML tags are being stripped because of the last line:

$message['body'][0] = drupal_html_to_text($body);

That function turns any HTML code into a rough approximation of your message but represented in plain text and ASCII.

Problem is, removing that line and making it $message['body'][0] = $body; won't help. Actions uses Drupal's system mail (see here), which calls drupal_html_to_text() *again*, so for Action-generated emails, you're sorta stuck with plain text, at least for now.

(Also note, if you're like me and just wanted to send normal text emails, there's a problem with the way drupal_html_to_text() is used with system mail, and it gets greedy (#298708: drupal_html_to_text() removes line endings) with line breaks, turning everything into a single line of text. There's an easy workaround (http://drupal.org/node/298708#comment-1376638) but it involves putting html into your Action. Not great, but it does the job, at least until system mail is modified to not use it. (#407452: Remove use of drupal_html_to_text() from system mails) )

Anyways, just confirming that ProfStein's code worked for me, although I removed the drupal_html_to_text() function from my version, because of the greediness, as mentioned above.

Richard Blackborder’s picture

subscribing
(thank you Ernesto and ProfStein)

mikeskull’s picture

Also getting same issue albeit on sending emails, this is makes workflow unusable for me, tried moving the trigger for the email send closer to the start of the workflow, only the %site_name and %username ones ever work. none of the fixes above work for me either.

Its just a simple workflow of user creates a node once created email gets sent to admin with details of the node. All works fine just have %title and stuff all over the email.

If you need any testing done just shout.

egbertb’s picture

Patch work for me, thanx.
Still have a comparable problem with the messages set, but there is no alter_message hook.
So now I have correct mails, but still very ugly uninformative messages in the page after saving.

sharplesa’s picture

Issue tags: +suggested patch
StatusFileSize
new898 bytes

Am I missing something? workflow_workflow is calling actions_do with a null $object at line 791.

Can't workflow just go ahead and set $object to $node? Attached is a patch introducing a simple addition that sets $objects[...]=$node iff $objects[...] is still empty after _trigger_normalize_node_context. Works beautifully and does away with the need for the creative patching going on above...

csc4’s picture

I'm struggling to understand the context and how to use it - the patch at #30 seems like a good enhancement.

punjabi’s picture

Patch #30 seems to work great for me.

sharplesa’s picture

Status: Reviewed & tested by the community » Needs review

Patch at #30 is simple and solves the issue. Please review and implement.

meba’s picture

Status: Needs review » Reviewed & tested by the community

If the patch works and is already tested, why moving back to need review?

sharplesa’s picture

Because the proposed patch seems to do way more than necessary, compared to the very simple patch I proposed at #30. I guess I was requesting that the community who reviewed the previous patch reconsider the work that I'd done and let me know if I'm off-base, or if this isn't a better solution than the previously accepted one.

Anonymous’s picture

#30 works for me!
Please implement!

Thanks much!

designerbrent’s picture

Priority: Normal » Critical

The patch in #30 works excellent for me.

I'm also elevating this to Critical as it seem that this module is not as useful without this functionality.

jumpfightgo’s picture

Patch worked for me too on production site, no problems yet (fingers crossed)! :)

WeaveGeek’s picture

Patch #30 worked for me too. Also on a production site. Thanks!

fschwiet’s picture

Patch 30 worked for me for both emails actions and user message actions.

I think there was reasonable pushback though as it is too general. It is always applying the node without knowing that is appropriate.

Before the patch, the trigger module uses $action_info['type'] to determine what tokens get replaced with action specific information. In the happy case it is $action_info['type']=='node' and we get the node info. In the case where the patch is applied, the value of $action_info['type']=='system'.

I'm new to Drupal, so not sure where to go with this. I'm going to use the patch in 30 though its been rejected.

tqvn2004’s picture

Subcribing

jvandyk’s picture

Status: Reviewed & tested by the community » Fixed

Modified patch from #30 committed to pass the node if the action type is 'system'. Will appear in 6.x-1.4.

Status: Fixed » Closed (fixed)
Issue tags: -suggested patch

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