You are here

function workflow_extensions_token_values in Workflow Extensions 7

Same name and namespace in other branches
  1. 6 workflow_extensions.module \workflow_extensions_token_values()

Implements hook_token_values().

Returning [workflow-state-age] for both node and workflow contexts as there seems to be an issue with using Workflow state as the data type argument in a Rule set. Such a Rule set won't show as available in a scheduled triggered rule. The Content (ie node) data type must be used instead.

File

./workflow_extensions.module, line 559
UI-related improvements to the Workflow module and tokens for Rules.

Code

function workflow_extensions_token_values($context, $object = NULL) {
  $values = array();
  switch ($context) {
    case 'node':
    case 'workflow':
      if (isset($object)) {
        $node = (object) $object;
        if (module_exists('workflow')) {
          $stamp = db_query_range("SELECT stamp FROM {workflow_node_history} WHERE nid = :nid ORDER BY stamp DESC", array(
            ':nid' => $node->nid,
          ))
            ->fetchField();
          $values['workflow-state-age'] = $stamp ? REQUEST_TIME - $stamp : 0;
        }
        $values['mod-since-seconds'] = $node->changed ? REQUEST_TIME - $node->changed : 0;
      }
      break;
  }
  return $values;
}