Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Since D6, many of our hooks have evolved to add a _alter version allowing after-the-fact altering of information.
One place where this is still missing is hook_xmlrpc().
The typical use case I envision for this is much the same as for hook_menu(), for instance implementing preprocessing features in front of existing xmlrpc web services without any need to alter their code. The implementation seems almost trivial:
Current, in xmlrpc.php
xmlrpc_server(module_invoke_all('xmlrpc'));
Possible change looks like it could be:
$services = module_invoke_all('xmlrpc');
drupal_alter('xmlrpc_alter', $services);
xmlrpc_server($services);
Comment | File | Size | Author |
---|---|---|---|
#19 | xmlrpc_656266_19.patch | 6.86 KB | fgm |
#17 | xmlrpc_656266_17.patch | 6.73 KB | fgm |
#14 | drupal.xmlrpc-alter.14.patch | 3.77 KB | sun |
#13 | 656266_13.patch | 928 bytes | fgm |
#12 | xmlrpc_alter.patch | 737 bytes | fgm |
Comments
Comment #2
fgmRerolling against today's head.
Comment #3
fgmRerolling against today's head.
Comment #4
Dries CreditAttribution: Dries commentedCommitted.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedI think what we want here is
GOOD:
drupal_alter('xmlrpc', $services);
BAD:
drupal_alter('xmlrpc_alter', $services);
If we leave as is, an implementation is too verbose. for example: poll_xmlprc_alter_alter()
Comment #6
fgmOops, typo...
Comment #7
fgmTo compensate for the typo, enhanced patch including API documentation.
Comment #8
Dries CreditAttribution: Dries commentedGood catch, Moshe, and thanks for the extra documentation with the fix, fgm. Committed to CVS HEAD.
Comment #10
fgmAny hope of seeing this backported ? It's exactly the same change on D6.
Comment #11
fgmJust found a limitation in this approach: default methods from the system package cannot be thus altered, because they are being injected in the call to includes/xmlrpcs.inc#xmlrpc_server(). The drupal_alter() needs to be performed after their injection instead of before as it currently is.
Comment #12
fgmHere is the D6 suggested patch, for a start
Comment #13
fgmAnd here is the D7 patch.
Comment #14
sunWe only link to drupal.org issues in very complex cases.
This means that we can revert the changes to xmlrpc.php.
Powered by Dreditor.
Comment #15
fgmOoops. Sorry I forgot the xmlrpc.php when rolling the patch !
Your comments are better worded, too. RTBC for me, but maybe we want to add a test ?
Comment #16
sfyn CreditAttribution: sfyn commentedI've reviewed the changes and tested the patch. I was able to write a module using the hook, add a method to the list of xmlrpc methods, plus retrieve it from another site.
+1 for the patch in #14
Comment #17
fgm@sfyn: thx for the review.
Here is a new version: same code, but adds a simpletest to hide a builtin method. The test would have failed with the patch from #3.
Comment #18
sunThanks!
phpDoc summaries should be on one line. See http://drupal.org/node/1354
We can shorten this to: Ensure that hook_xmlrpc_alter() can hide methods.
The variable should at least be in the namespace of the xmlrpc_test module, i.e., starting with "xmlrpc_test_". Most often, we just re-use the hook implementation name for the variable in such situations, i.e., "xmlrpc_test_xmlrpc_alter" as variable name.
This comment, in the middle of nothing, make no sense for me. It does not explain anything that wouldn't be visible from the code itself. I guess you rather meant to put one inline comment above each section/chapter:
// Ensure xmlrpc_test_xmlrpc_alter() is disabled and retrieve regular list of methods.
...
// Enable the alter hook and retrieve the list of methods again.
...
s/Implement/Implements/
We do not document return values for hook implementations. See Doxygen coding standards I linked to above.
Should be isset(). Never use is_null().
Powered by Dreditor.
Comment #19
fgmRerolled; thanks for your fast comments.
I kept the mention about builtin methods because this was precisely what failed in the previous implementation. Not sure whether it is useful or not ?
Regarding isset/is_null, I suppose this is for performance reasons (non-function vs function), but maybe there is something else ?
Comment #21
fgmFWIW failure appears to be in a form API change committed this afternoon, not related with this patch.
Comment #22
sun#19: xmlrpc_656266_19.patch queued for re-testing.
Comment #23
sun#19: xmlrpc_656266_19.patch queued for re-testing.
Comment #24
sunPlease wait for the bot to come back green.
Comment #25
webchickNew hook = feature request.
Since this doesn't break BC, it's possible this is one of those things we could back-port from D8 to D7 later on.
Comment #26
fgm@webchick: this is not a feature request, the hook has been in D7 core since Dries committed it in december, but included a bug which this new version fixes.
Accordingly, resetting to D7/bug. Hope I'm not misinterpreting your intent.
Comment #27
webchickAh, ok. I saw the +drupal_alter() but missed the -drupal_alter() up above.
We should probably adjust the issue title so no one else makes that mistake.
Comment #28
webchickComment #29
fgmAdjusting title to match current situation.
Comment #30
sunSigh. No comment on the last 10 comments.
Still RTBC.
Comment #31
sun#19: xmlrpc_656266_19.patch queued for re-testing.
Comment #32
sunAlthough badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).
Comment #33
fgm@sun: could you explain which rule applies ? This is a bug to an existing D7 feature. Are we only fixing bugs in D8 now ? And a rather bad one, because it removes most of the interest of the hook: if it is impossible to use HXA to alter/mask the builtin methods, the fact the system.multicall is not altered means any call to any method, even hidden, remains possible just by multicalling it in a single call array.
Comment #34
Damien Tournoud CreditAttribution: Damien Tournoud commentedOnly feature requests and tasks can be assigned to D8 for now, because the Drupal 8 tree is not opened yet.
Comment #35
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.