? example_xmlrpc_alter.patch
? xmlrpc_example/client.py
Index: xmlrpc_example/xmlrpc_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/xmlrpc_example/xmlrpc_example.module,v
retrieving revision 1.3
diff -u -p -r1.3 xmlrpc_example.module
--- xmlrpc_example/xmlrpc_example.module	10 Feb 2010 23:57:51 -0000	1.3
+++ xmlrpc_example/xmlrpc_example.module	27 Aug 2010 09:03:03 -0000
@@ -13,6 +13,7 @@
  * is probably the more common way to do XMLRPC at this time.
  *
  * @see hook_xmlrpc()
+ * @see hook_xmlrpc_alter()
  * @see xmlrpc()
  * @see xmlrpc_errno()
  * @see xmlrpc_error_msg()
@@ -28,25 +29,24 @@
  * @see hook_xmlrpc()
  */
 function xmlrpc_example_xmlrpc() {
-   $methods[] =  array(
-      'xmlrpc_example.add',
-      '_xmlrpc_example_add',
-      array(
-        'int', // the type of the return value
-        'int', // the type of the first argument
-        'int',  // the type of the second argument
-      ),
-      t('Returns the sum of the two arguments.')
+  $methods[] =  array(
+    'xmlrpc_example.add',
+    '_xmlrpc_example_add',
+    array(
+      'int', // the type of the return value
+      'int', // the type of the first argument
+      'int',  // the type of the second argument
+    ),
+    t('Returns the sum of the two arguments. Provided by the hook_xmlrpc() implementation.')
   );
   $methods[] =  array(
-      'xmlrpc_example.subtract',
-      '_xmlrpc_example_subtract',
-      array('int', 'int', 'int'),
-      t('Return difference of the two arguments.')
+    'xmlrpc_example.bad',
+    '_xmlrpc_example_unimplemented',
   );
 
   return $methods;
 }
+
 /**
  * Sum the two arguments.
  * @param $num1
@@ -85,6 +85,36 @@ function _xmlrpc_example_subtract($num1,
   }
 }
 
+/**
+ * Implements hook_xmlrpc_alter() to add a method after the fact.
+ *
+ * This is what you would use to modify the information for a method provided
+ * by another module, like changing its callback or even hiding it for security
+ * reasons. In this example, we are using it to add a second method to our own
+ * module and remove the "bad" method.
+ *
+ * @see hook_xmlrpc_alter()
+ */
+function xmlrpc_example_xmlrpc_alter(&$methods) {
+  // First, locate the "bad" method and remove it from the list of methods
+  $offset = -1;
+  foreach ($methods as $index => $method) {
+    if ($method[0] === 'xmlrpc_example.bad') {
+      $offset = $index;
+    }
+  }
+  if ($offset != -1) {
+    unset($methods[$offset]);
+  }
+
+  // Second, add a new method in the xmlrpc_example package
+  $methods[] =  array(
+    'xmlrpc_example.subtract',
+    '_xmlrpc_example_subtract',
+    array('int', 'int', 'int'),
+    t('Return difference of the two arguments. Provided by the hook_xmlrpc_alter() implementation.')
+  );
+}
 
 // Now begins the client/UI portion of the module.
 /**
@@ -178,4 +208,3 @@ function xmlrpc_example_subtract_submit(
     drupal_set_message(t("The XMLRPC server returned this response: @response", array('@response' => print_r($result, TRUE))));
   }
 }
-
