You are here

function workflow_token_info in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow.tokens.inc \workflow_token_info()

Implements hook_token_info().

Adds tokens and token types, for Field, Workflow, State and Transition, using the names of the entities from Workflow module. Lots of tokens are already defined via entity_properties. D7: a dependency on entity_token exists.

See also

workflow_entity_property_info_alter()

File

./workflow.tokens.inc, line 74
Tokens hooks for Workflow module.

Code

function workflow_token_info() {
  if (!module_exists('entity_token')) {
    return array();
  }

  /*
   * Token types.
   */
  $types['WorkflowField'] = array(
    'name' => t('Workflows'),
    'description' => t('Tokens related to workflows.'),
    'needs-data' => 'entity',
  );
  $types['WorkflowTransition'] = array(
    'name' => t('Workflow Transition'),
    'description' => t('Tokens related to workflow transitions.'),
    // 'needs-data' => 'entity',
    'needs-data' => 'WorkflowField',
  );
  $types['WorkflowState'] = array(
    'name' => t('Workflow State'),
    'description' => t('Tokens related to workflow state.'),
    'needs-data' => 'WorkflowTransition',
  );
  $types['Workflow'] = array(
    'name' => t('Workflow'),
    'description' => t('Tokens related to workflows.'),
    'needs-data' => 'WorkflowTransition',
  );

  /*
   * Chained tokens for nodes.
   */
  $last_transition = array(
    'name' => t('Workflow last transition'),
    'description' => t('Last workflow state transition of content.'),
    'type' => 'WorkflowTransition',
    'module' => 'workflow',
  );

  // Add a token tree to each core entity type. This allows easy reference
  // in the majority of cases.
  $workflow_field['last-transition'] = $last_transition;
  $entity['last-transition'] = $last_transition;
  $user['last-transition'] = $last_transition;
  $node['last-transition'] = $last_transition;
  $term['last-transition'] = $last_transition;
  $return = array(
    'types' => $types,
    'tokens' => array(
      // 'entity' => $entity, // #2272121
      'user' => $user,
      'node' => $node,
      'term' => $term,
      'WorkflowField' => $workflow_field,
    ),
  );
  return $return;
}