function hosting_nodeapi in Hostmaster (Aegir) 6
Implementation of hook_nodeapi().
This function redirects to hosting_nodeapi_$nodetype_$op calls, to save ourselves from an incessant amount of intricately nested code, and allow easier extension / maintenance.
See also
File
- modules/
hosting/ hosting.module, line 185 - Hosting module.
Code
function hosting_nodeapi(&$node, $op, $arg1, $arg2) {
global $user;
$return = array();
if (in_array($node->type, hosting_context_node_types())) {
switch ($op) {
case 'presave':
if (!$node->uid) {
$node->uid = $user->uid;
}
break;
case 'load':
$return = db_fetch_array(db_query("SELECT name AS hosting_name FROM {hosting_context} WHERE nid = %d", $node->nid));
if ($return === FALSE) {
// Should only happen on install
$return = array();
}
break;
case 'delete':
db_query("DELETE FROM {hosting_context} WHERE nid = %d", $node->nid);
break;
}
}
// We need to practically re-invent module_invoke_all here because
// we have to pass the node as a reference.
$hook = "nodeapi_" . $node->type . "_" . str_replace(" ", "_", $op);
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$result = $function($node, $arg1, $arg2);
if (isset($result) && is_array($result)) {
$return = array_merge_recursive($return, $result);
}
else {
if (isset($result)) {
$return[] = $result;
}
}
}
return $return;
}