Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.523 diff -u -F^f -r1.523 node.module --- modules/node.module 25 Aug 2005 21:22:00 -0000 1.523 +++ modules/node.module 27 Aug 2005 08:21:02 -0000 @@ -203,25 +203,25 @@ function node_teaser($body, $format = NU } /** - * Determine the module that defines the node type of the given node. + * Determine the basename for hook_load etc. * * @param &$node * Either a node object, a node array, or a string containing the node type. * @return - * A string containing the name of the defining module. + * A string containing the basename for the node type. */ -function node_get_module_name($node) { +function node_get_base_name($node) { if (is_array($node)) { $type = $node['type']; } - else if (is_object($node)) { + elseif (is_object($node)) { $type = $node->type; } - else if (is_string($node)) { + elseif (is_string($node)) { $type = $node; } - $modules = node_list(); + $types = node_list(); return $modules[$type]; } @@ -230,24 +230,32 @@ function node_get_module_name($node) { * Get a list of all the defined node types. * * @return - * An associate array of consisting of (node type, module name) pairs for all node types. + * An associate array of consisting of + * computer readable node type => array(human readable node type, basename) + * pairs for all node types. */ function node_list() { static $types = array(); if (empty($types)) { - foreach (module_list() as $module) { - if (module_hook($module, 'node_name')) { - $module_types = module_invoke($module, 'node_types'); - if (is_array($module_types)) { - foreach ($module_types as $type) { - $types[$type] = $module; + foreach (module_implements('node_name') as $module) { + $node_names = module_invoke($module, 'node_name'); + if (is_array($node_names)) { + foreach ($node_names as $key => $value) { + if (is_numeric($key)) { + $types[$module] = array($value, $module); + } + elseif (is_string($value)) { + $types[$key] = array($value, $module); + } + else { + $types[$key] = $value; } - } - else { - $types[$module] = $module; } } + else { + $types[$module] = array($value, $module); + } } } return $types; @@ -264,9 +272,7 @@ function node_list() { * TRUE iff the $hook exists in the node type of $node. */ function node_hook(&$node, $hook) { - $function = node_get_module_name($node) ."_$hook"; - - return function_exists($function); + return module_hook(node_get_base_name($node), $hook); } /** @@ -282,9 +288,8 @@ function node_hook(&$node, $hook) { * The returned value of the invoked hook. */ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { - $function = node_get_module_name($node) ."_$hook"; - - if (function_exists($function)) { + if (node_hook($node, $hook)) { + $function = node_get_base_name($node) ."_$hook"; return ($function($node, $a2, $a3, $a4)); } } @@ -1279,7 +1284,7 @@ function node_form($edit) { // Get the node-specific bits. // We can't use node_invoke() because $param must be passed by reference. - $function = node_get_module_name($edit) .'_form'; + $function = node_get_base_name($edit) .'_form'; $param = array(); if (function_exists($function)) { $form .= $function($edit, $param); @@ -1865,7 +1870,7 @@ function node_access($op, $node = NULL, // Can't use node_invoke(), because the access hook takes the $op parameter // before the $node parameter. - $access = module_invoke(node_get_module_name($node), 'access', $op, $node); + $access = module_invoke(node_get_base_name($node), 'access', $op, $node); if (!is_null($access)) { return $access; }