? example_xmlrpc_alter.patch
? examples_xmlrpc_894972.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.4
diff -u -p -r1.4 xmlrpc_example.module
--- xmlrpc_example/xmlrpc_example.module	27 Aug 2010 10:37:15 -0000	1.4
+++ xmlrpc_example/xmlrpc_example.module	27 Aug 2010 14:05:53 -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()
@@ -25,6 +26,11 @@
  *
  * Provides Drupal with an array to map XML-RPC callbacks to the
  * functions implemented by this module.
+ *
+ * There are two ways to define XML-RPC callbacks in hook_xmlrpc(), but the
+ * first one in this example is better because it allows online help to be
+ * defined.
+ *
  * @see hook_xmlrpc()
  */
 function xmlrpc_example_xmlrpc() {
@@ -38,15 +44,12 @@ function xmlrpc_example_xmlrpc() {
     ),
     t('Returns the sum of the two arguments.')
   );
-  $methods[] =  array(
-    'xmlrpc_example.subtract',
-    '_xmlrpc_example_subtract',
-    array('int', 'int', 'int'),
-    t('Return difference of the two arguments.')
-  );
+
+  $methods['xmlrpc_example.bad'] = '_xmlrpc_example_unimplemented';
 
   return $methods;
 }
+
 /**
  * Sum the two arguments.
  * @param $num1
@@ -75,7 +78,7 @@ function _xmlrpc_example_add($num1, $num
  *
  * @see xmlrpc_error()
  */
-function _xmlrpc_example_subtract($num1, $num2) {
+function _xmlrpc_example_substract($num1, $num2) {
   $difference = $num1 - $num2;
   if ($difference >= 0) {
     return $difference;
@@ -85,6 +88,28 @@ 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, remove the "bad" method from the list of methods
+  unset($methods['xmlrpc_example.bad']);
+
+  // Second, add a new method in the xmlrpc_example package
+  $methods[] =  array(
+    'xmlrpc_example.substract',
+    '_xmlrpc_example_substract',
+    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.
 /**
@@ -102,7 +127,7 @@ function xmlrpc_example_menu() {
 }
 
 /**
- * Present a form that uses xmlrpc to add or subtract.
+ * Present a form that uses xmlrpc to add or substract.
  */
 function xmlrpc_example_demo_form() {
   $form = array();
@@ -129,10 +154,10 @@ function xmlrpc_example_demo_form() {
     '#value' => t("Add the integers"),
     '#submit' => array('xmlrpc_example_add_submit'),
   );
-  $form['subtract'] = array(
+  $form['substract'] = array(
     '#type' => 'submit',
-    '#value' => t("Subtract the integers"),
-    '#submit' => array('xmlrpc_example_subtract_submit'),
+    '#value' => t("Substract the integers"),
+    '#submit' => array('xmlrpc_example_substract_submit'),
   );
   return $form;
 }
@@ -162,7 +187,7 @@ function xmlrpc_example_add_submit($form
 }
 
 /**
- * Submit for subtraction: Call the xmlrpc method and report the result.
+ * Submit for substraction: Call the xmlrpc method and report the result.
  * @param $form
  * @param $form_state
  *
@@ -170,9 +195,9 @@ function xmlrpc_example_add_submit($form
  * @see xmlrpc_errno()
  * @see xmlrpc_error_msg()
  */
-function xmlrpc_example_subtract_submit($form, &$form_state) {
+function xmlrpc_example_substract_submit($form, &$form_state) {
   $server = url($GLOBALS['base_url'] . "/xmlrpc.php");
-  $result = xmlrpc($server, array('xmlrpc_example.subtract' => array(
+  $result = xmlrpc($server, array('xmlrpc_example.substract' => array(
     (int) $form_state['values']['num1'],
     (int) $form_state['values']['num2'],
   )));
Index: xmlrpc_example/xmlrpc_example.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/xmlrpc_example/xmlrpc_example.test,v
retrieving revision 1.2
diff -u -p -r1.2 xmlrpc_example.test
--- xmlrpc_example/xmlrpc_example.test	27 Aug 2010 10:37:15 -0000	1.2
+++ xmlrpc_example/xmlrpc_example.test	27 Aug 2010 14:05:53 -0000
@@ -39,8 +39,8 @@ class XmlrpcExampleTestCase extends Drup
     $result = xmlrpc($this->xmlrpc_url, array('xmlrpc_example.add' => array(3, 4)));
     $this->assertEqual($result, 7, t('Successfully added 3+4 = 7'));
 
-    $result = xmlrpc($this->xmlrpc_url, array('xmlrpc_example.subtract' => array(4, 3)));
-    $this->assertEqual($result, 1, t('Successfully subtracted 4-3 = 1'));
+    $result = xmlrpc($this->xmlrpc_url, array('xmlrpc_example.substract' => array(4, 3)));
+    $this->assertEqual($result, 1, t('Successfully substracted 4-3 = 1'));
 
     // Now test the UI.
     $edit = array('num1' => 3, 'num2' => 5);
@@ -48,7 +48,7 @@ class XmlrpcExampleTestCase extends Drup
     $this->assertText(t("The XMLRPC server returned this response: @num", array('@num' => 8)));
 
     $edit = array('num1' => 8, 'num2' => 3);
-    $this->drupalPost('examples/xmlrpc_example', $edit, t('Subtract the integers'));
+    $this->drupalPost('examples/xmlrpc_example', $edit, t('Substract the integers'));
     $this->assertText(t("The XMLRPC server returned this response: @num", array('@num' => 5)));
   }
 }
