Hi there,
I've been writing a custom review process, including review period scheduling for a site I'm building and I was having to write custom actions into my own module for workflow-ng to pick up. Thankfully with v 1.4 I am supposed to be able to put custom php write into an action in the UI and have it evaluated tokens and all.
Well this is what I have to say; It does not work.
Each time I try to include a token in a php script I get a php syntax error on execution, fine I can just write the code as variables.
But it says on the help text under the php body that to save variables I need to add: return array("node" => $node);
To the end of my code. This also brings up a PHP syntax error of the type 'unexpected T_Return', and if the return is not included there are no changes to the node variables.
Anyway for your consideration here is the custom code I have, first as variables and second as tokens, please tell me if I'm doing anything wrong or is there a bug in 1.4?
example 1(variables):
// Variables for this action
$period = ($node->field_review_period[0]['value']) * 60 * 60 * 24; // Review period in seconds
$expire_datestamp = time() + $period; // Review expiration date as a unix timestamp
// Set sent for review date to NOW
$node->field_sent_for_review[0]["value"] = date("Y-m-d\TH:i:s");
// Set expiration field to expiration date
$node->field_review_period_expires[0]["value"] = date("Y-m-d\TH:i:s", $expire_datestamp);
// Set Schedule for cclink0 to expiration date
$event_name = "cclink0";
cclinks_set_date($node, $event_name, $expire_datestamp);
// Increment review cycle counter
$node->field_review_cycle[0]["value"] += 1
//submit node update
return array("node" => $node);
example 2(tokens):
// Variables for this action
$period = ([node:field_review_period-raw]) * 60 * 60 * 24; // Review period in seconds
$expire_datestamp = time() + $period; // Review expiration date as a unix timestamp
// Set sent for review date to NOW
[node:field_sent_for_review-value] = date("Y-m-d\TH:i:s");
// Set expiration field to expiration date
[node:field_review_period_expires-value] = date("Y-m-d\TH:i:s", $expire_datestamp);
// Set Schedule for cclink0 to expiration date
$event_name = "cclink0";
cclinks_set_date($node, $event_name, $expire_datestamp);
// Increment review cycle counter
$node->[node:field_review_cycle-formatted] += 1
//submit node update
return array("node" => $node);
Comments
Comment #1
ramriot commentedI put the above down to late night code blindness, I missed a ; off the end of line 17.
Also thanks for someone updating my code and adding in the
tags, Please note in the above that in the module UI this is not needed and was not part of my code.Well today after correcting the above syntax error, replacing all the tokens with their respective variables and using node_save instead of return array, the action now completes ok.
There still seems to be a bug though in using tokens at the beginnings of lines and the use of return at the end of the action.
I'm going to carry on using this for now, but would appreciate any input on the use of token replacement and $node array submission.
Current working code:
Comment #2
fagoSurely, your token code can't work.
e.g.:
[node:field_review_period_expires-value] = date("Y-m-d\TH:i:s", $expire_datestamp..
results in
32423432(value)242342 = date("Y-m-d\TH:i:s", $expire_datestamp.. -> which is no valid php -> syntax error
you can use it like this for numbers
$value = [node:field_review_period_expires-value];
or this for strings:
$value = '[node:field_review_period_expires-value]';
However, you are right with the saving of the arguments. It wasn't working correctly previously, so I've fixed it. Use the latest dev snapshot to get the fix.
Comment #3
fagoyour use case sounds really interesting. It would be great if you could write it up as a tutorial or so.
Comment #4
ramriot commentedThanks for the interest, Once we go live with the site I will certainly consider it.
By the way we decided in the end to use a custom module to store all the actions to be triggered by specific events. It makes for much easier debugging and keeping track of code revisions.
Comment #5
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.