From e99e0988f469e61aecb4367f0ef21cee6d17fb16 Mon Sep 17 00:00:00 2001
From: Derek Wright <git@dwwright.net>
Date: Sat, 23 Jun 2012 02:30:46 -0500
Subject: [PATCH] Issue #1256478 by dww: Added API documention via clone.api.php.

---
 clone.api.php   |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 clone.module    |    3 +--
 clone.pages.inc |    6 ------
 3 files changed, 48 insertions(+), 8 deletions(-)
 create mode 100644 clone.api.php

diff --git a/clone.api.php b/clone.api.php
new file mode 100644
index 0000000..4a1ffa8
--- /dev/null
+++ b/clone.api.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * @file
+ * API documentation for the Node clone module.
+ */
+
+/**
+ * Alter the node before saving a clone.
+ *
+ * @param $node
+ *   Reference to the fully loaded node object being saved (the clone) that
+ *   can be altered as needed.
+ * @param array $context
+ *   An array of context describing the clone operation. The keys are:
+ *   - 'method' : Can be either 'prepopulate' or 'save-edit'.
+ *   - 'original_node' : The original fully loaded node object being cloned.
+ *
+ * @see clone_node_save()
+ * @see drupal_alter()
+ */
+function hook_clone_node_alter(&$node, $context) {
+  if ($context['original_node']->type = 'special') {
+    $node->special = special_something();
+  }
+}
+
+/**
+ * Alter the access to the ability to clone a given node.
+ *
+ * @param bool $access
+ *   Reference to the boolean determining if cloning should be allowed on a
+ *   given node.
+ * @param $node
+ *   The fully loaded node object being considered for cloning.
+ *
+ * @see clone_access_cloning()
+ * @see drupal_alter()
+ */
+function hook_clone_access_alter(&$access, $node) {
+  global $user;
+  // Only allow cloning of nodes posted to groups you belong to.
+  // This function doesn't really exist, but you get the idea...
+  if (!og_user_is_member_of_group_the_node_is_in($user, $node)) {
+    $access = FALSE;
+  }
+}
diff --git a/clone.module b/clone.module
index 29003dd..b442854 100644
--- a/clone.module
+++ b/clone.module
@@ -58,8 +58,7 @@ function clone_access_cloning($node) {
   $access = clone_is_permitted($node->type) && (user_access('clone node') || ($user->uid && ($node->uid == $user->uid) && user_access('clone own nodes')));
   // Make sure the user can view the original node content, and create a new one..
   $access = $access && node_access('view', $node) && node_access('create', $node->type);
-  // Let other modules alter this - for exmple to only allow some users
-  // to clone specific nodes or types.
+  // Let other modules alter this.
   drupal_alter("clone_access", $access, $node);
   return $access;
 }
diff --git a/clone.pages.inc b/clone.pages.inc
index a15ba00..d4ae902 100644
--- a/clone.pages.inc
+++ b/clone.pages.inc
@@ -167,9 +167,6 @@ function clone_node_prepopulate($original_node) {
         }
       }
       // Let other modules do special fixing up.
-      // The function signature is: hook_clone_node_alter(&$node, $context)
-      // $context is an array with two elements, 'method' and 'original_node',
-      // where 'method' is either 'prepopulate' or 'save-edit'.
       $context = array('method' => 'prepopulate', 'original_node' => $original_node);
       drupal_alter('clone_node', $node, $context);
       // Make sure the file defining the node form is loaded.
@@ -216,9 +213,6 @@ function clone_node_save($nid) {
         }
       }
       // Let other modules do special fixing up.
-      // The function signature is: hook_clone_node_alter(&$node, $context)
-      // $context is an array with two elements, 'method' and 'original_node',
-      // where 'method' is either 'prepopulate' or 'save-edit'.
       $context = array('method' => 'save-edit', 'original_node' => $original_node);
       drupal_alter('clone_node', $node, $context);
 
-- 
1.7.3.5

