From b563197f6b051edbadf273ac399e841cb6addda1 Mon Sep 17 00:00:00 2001
From: William Hearn <sylus1984@gmail.com>
Date: Mon, 8 Feb 2016 22:23:55 -0500
Subject: [PATCH] Issue #2662600 by sylus: Workbench Moderation Revision ID
 argument context

---
 plugins/arguments/workbench_rid.inc | 57 +++++++++++++++++++++++++++++++++++++
 workbench_moderation.module         |  3 ++
 2 files changed, 60 insertions(+)
 create mode 100644 plugins/arguments/workbench_rid.inc

diff --git a/plugins/arguments/workbench_rid.inc b/plugins/arguments/workbench_rid.inc
new file mode 100644
index 0000000..dc23d5d
--- /dev/null
+++ b/plugins/arguments/workbench_rid.inc
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @file
+ *
+ * Plugin to provide an argument handler for a node revision id
+ */
+
+/**
+ * Plugins are described by creating a $plugin array which will be used
+ * by the system that includes this file.
+ */
+$plugin = array(
+  'title' => t("Workbench Revision: ID"),
+  'keyword' => 'revision',
+  'description' => t('Creates a node context from a workbench revision ID argument.'),
+  'context' => 'workbench_moderation_argument_workbench_rid_context',
+  'placeholder form' => array(
+    '#type' => 'textfield',
+    '#description' => t('Enter the revision ID of a node for this argument'),
+  ),
+);
+
+/**
+ * Discover if this argument gives us the node we crave.
+ */
+function workbench_moderation_argument_workbench_rid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
+  // If unset it wants a generic, unfilled context.
+  if ($empty) {
+    return ctools_context_create_empty('node');
+  }
+
+  // We can accept either a node object or a pure nid.
+  if (is_object($arg)) {
+    return ctools_context_create('node', $arg);
+  }
+
+  if (!is_numeric($arg)) {
+    return FALSE;
+  }
+
+  $node = node_load($arg);
+
+  // Is there a current revision?
+  if (isset($node->workbench_moderation['current']->vid)) {
+    // Ensure that we will return the current revision
+    if ($node->vid != $node->workbench_moderation['current']->vid) {
+      $node = node_load($node->nid, $node->workbench_moderation['current']->vid);
+    }
+  }
+
+  if (!$node) {
+    return FALSE;
+  }
+
+  return ctools_context_create('node', $node);
+}
diff --git a/workbench_moderation.module b/workbench_moderation.module
index d8fa4b6..a0c850d 100644
--- a/workbench_moderation.module
+++ b/workbench_moderation.module
@@ -2351,6 +2351,9 @@ function workbench_moderation_set_state_action($node, $context) {
  * where our task and task_handler plugins are.
  */
 function workbench_moderation_ctools_plugin_directory($owner, $plugin_type) {
+  if ($owner == 'ctools') {
+    return 'plugins/' . $plugin_type;
+  }
   if ($owner == 'page_manager') {
     return 'plugins/page_manager/' . $plugin_type;
   }
-- 
2.3.8 (Apple Git-58)

