From 7678b86e827c9844dfeb2f071f10ee465c9c17ff Mon Sep 17 00:00:00 2001
From: Ron Shimshock <ron@shimshockgroup.com>
Date: Mon, 31 Aug 2015 20:41:29 -0500
Subject: [PATCH] Issue #2144993 - Workbench moderation tokens

---
 workbench_moderation.tokens.inc | 71 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 workbench_moderation.tokens.inc

diff --git a/workbench_moderation.tokens.inc b/workbench_moderation.tokens.inc
new file mode 100644
index 0000000..3f7e9c6
--- /dev/null
+++ b/workbench_moderation.tokens.inc
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @file
+ * Token integration for the workbench_moderation module.
+ */
+
+/**
+ * Implements hook_token_info().
+ */
+function workbench_moderation_token_info() {
+  $info['types']['workbench-moderation'] = array(
+    'name' => t('Workbench Moderation'),
+    'description' => t('Grouping of Workbench Moderation tokens.'),
+    'needs-data' => 'node',
+  );
+  $info['tokens']['node']['workbench-moderation'] = array(
+    'name' => t('Workbench Moderation'),
+    'description' => t('Tokens related to moderation of Workbench nodes.'),
+    'type' => 'workbench-moderation',
+  );
+
+  $info['tokens']['workbench-moderation']['new-state-name'] = array(
+    'name' => t('Current moderation state name'),
+    'description' => t('Machine name of the current Workbench Moderation state for the node.'),
+  );
+  $info['tokens']['workbench-moderation']['new-state-label'] = array(
+    'name' => t('Current moderation state label'),
+    'description' => t('Label for the current workbench Moderation state for the node.'),
+  );
+  $info['tokens']['workbench-moderation']['previous-state-name'] = array(
+    'name' => t('Previous moderation state name'),
+    'description' => t('Machine name for the previous Workbench Moderation state for the node.'),
+  );
+  $info['tokens']['workbench-moderation']['previous-state-label'] = array(
+    'name' => t('Previous moderation state label'),
+    'description' => t('Label for the previous Workbench Moderation state for the node.'),
+  );
+  return $info;
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function workbench_moderation_tokens($type, $tokens, array $data = array(), array $options = array()) {
+  $replacements = array();
+
+  if ($type == 'node' && !empty($data['node'])) {
+    $node = $data['node'];
+    if (is_object($node) && property_exists($node, 'workbench_moderation') && isset($node->workbench_moderation['current'])) {
+      $state = $node->workbench_moderation['current'];
+      foreach ($tokens as $name => $original) {
+        switch ($name) {
+          case 'workbench-moderation:new-state-name':
+            $replacements[$original] = $state->state;
+            break;
+          case 'workbench-moderation:new-state-label':
+            $replacements[$original] = workbench_moderation_state_label($state->state);
+            break;
+          case 'workbench-moderation:previous-state-name':
+            $replacements[$original] = $state->from_state;
+            break;
+          case 'workbench-moderation:previous-state-label':
+            $replacements[$original] = workbench_moderation_state_label($state->from_state);
+            break;
+        }
+      }
+    }
+  }
+
+  return $replacements;
+}
-- 
2.5.0

