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

dgtlmoon’s picture

actually - could be used to pragmatically choose a new workflow path/state route depending on some tests.

dgtlmoon’s picture

could 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

coupet’s picture

quite interesting! where do you suggest we add this? actions.inc or actions.module

dgtlmoon’s picture

Yeh sure, or add the ability to select which state to move to as well as the code?

mfredrickson’s picture

This should be added to the Actions Snippets page:

http://drupal.org/node/48737

dgtlmoon’s picture

Added a childpage there but its not showing up in the list.

http://drupal.org/node/71586

mfredrickson’s picture

You 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

Christoph C. Cemper’s picture

interesting!

Pomliane’s picture

Status: Needs review » Closed (won't fix)

This 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.