%title does not work for "display message to user"
nektir - May 1, 2008 - 22:35
| Project: | Workflow |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
| Issue tags: | suggested patch |
Description
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...

#1
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?
#2
I'm running into the issue when trying to send mail using actions. Did you ever get this figured out?
#3
Nope, still find any solutions... I just used generic terms instead of the tokens
#4
I haven't tried it yet.. but maybe this will help? http://drupal.org/node/195773
#5
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.
#6
I have changed the project because the workflow module include the triggerunlock functionalities.
#7
Is this going to be addressed. It seems that sending email is a popular use of workflow.
#8
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).
#9
Should this be moved to the D7 queue? or D6 queue?
#10
I'm having the same issue. I'm unable to send useful emails because of it. Does anyone have a patch for this?
#11
I have the same problem. Are you saying that triggerunlock will fix it??
#12
No, jvandyk is saying it is a bug in the Drupal 6 core that would need to be addressed.
#13
How do I apply the fix from #8 in my Drupal 6 installation?
#14
subscribing
#15
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
#16
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!
#17
The patch is duplicate to #339591: Sending mail and displaying a message in a trigger doesn't honor tokens
#18
lol! beaten to it by a day - nice work though.
#19
Fixed by this: http://drupal.org/node/339591
#20
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.
--project followup subject--
Automatically closed -- issue fixed for two weeks with no activity.
#21
Automatically closed -- issue fixed for two weeks with no activity.
#22
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?
#23
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);
}
}
#24
Patch #23 works really well for me. Great contribution ProfStein! No hacking core. :)
#25
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?
#26
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 callsdrupal_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.
#27
subscribing
(thank you Ernesto and ProfStein)
#28
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.
#29
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.
#30
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...
#32
I'm struggling to understand the context and how to use it - the patch at #30 seems like a good enhancement.
#33
Patch #30 seems to work great for me.
#34
Patch at #30 is simple and solves the issue. Please review and implement.
#35
If the patch works and is already tested, why moving back to need review?
#36
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.