Closed (won't fix)
Project:
Actions
Version:
5.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Mar 2006 at 04:13 UTC
Updated:
3 Feb 2013 at 19:42 UTC
Very handy, create lock files, do SOAP/XMLRPC calls etc
function action_eval_php($op, $edit = array(), $node) {
switch($op) {
case 'metadata':
return array(
'description' => t('Execute PHP, optionally move to next state'),
'type' => t('PHP Code'),
'batchable' => false,
'configurable' => true,
);
case 'do':
// get unique function name so we dont get function collisions
eval($edit['evalcode']);
$functionID=$edit['functionID'];
$_action_eval="_action_do_eval_$functionID";
// log
watchdog('action', t('Calling PHP eval code function %eval', array('%eval' => $_action_eval)));
$ret=$_action_eval($op, $edit, $node);
if (function_exists("action_workflow_execute_transition")) {
if($ret==true && $edit['executeTransition']==true) {
action_workflow_execute_transition($op, $edit, &$node);
}
}
break;
// return an HTML config form for the action
case 'form':
// default values for form
$functionID=$edit["functionID"];
if (!isset($edit['functionID'])) $functionID=md5(microtime());
if (!isset($edit['evalcode'])) $edit['evalcode'] = "function _action_do_eval_$functionID(\$op, \$edit = array(), \$node) {\n\n \treturn true;\n }";
if (!isset($edit['executeTransition'])) $edit['executeTransition'] = 0;
$form['evalcode'] = array(
'#type' => 'textarea',
'#title' => t('PHP Code'),
'#default_value' => $edit['evalcode'],
'#cols' => '80',
'#rows' => '20',
'#required' => true,
'#description' => t('The code to be run'),
);
$form['functionID'] = array(
'#type' => 'hidden',
'#default_value' => $functionID,
'#required' => true
);
$form['executeTransition'] = array(
'#type' => 'checkbox',
'#title' => t('Execute transition to next state if _action_do_eval_...() returns true?'),
'#default_value' => $edit['executeTransition'],
);
return $form;
// validate the HTML form
case 'validate':
$errors = array();
foreach ($errors as $name => $message) {
form_set_error($name, $message);
}
return count($errors) == 0;
// process the HTML form to store configuration
case 'submit':
$params = array(
'evalcode' => $edit['evalcode'],
'functionID' => $edit['functionID'],
'executeTransition' => $edit['executeTransition']
);
return $params;
}
}
Comments
Comment #1
dgtlmoon commentedactually - could be used to pragmatically choose a new workflow path/state route depending on some tests.
Comment #2
dgtlmoon commentedcould also be used to move a node to a "shipped" state if you have some barcode scanner triggering the workflow "update" event i think, which it could then fire off an email
Comment #3
coupet commentedquite interesting! where do you suggest we add this? actions.inc or actions.module
Comment #4
dgtlmoon commentedYeh sure, or add the ability to select which state to move to as well as the code?
Comment #5
mfredrickson commentedThis should be added to the Actions Snippets page:
http://drupal.org/node/48737
Comment #6
dgtlmoon commentedAdded a childpage there but its not showing up in the list.
http://drupal.org/node/71586
Comment #7
mfredrickson commentedYou might have to wait for an admin to approve it. If that doesn't happen in 24 hours, you should probably file an issue against drupal.org
Thanks for adding this to the actions snippets library.
-M
Comment #8
Christoph C. Cemper commentedinteresting!
Comment #9
pomliane commentedThis version of Actions is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.
This issue has been automagically closed by a script.