? modules/simplenode.module Index: modules/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog.module,v retrieving revision 1.223 diff -u -F^f -r1.223 blog.module --- modules/blog.module 25 Aug 2005 21:14:16 -0000 1.223 +++ modules/blog.module 27 Aug 2005 11:12:04 -0000 @@ -9,7 +9,7 @@ /** * Implementation of hook_node_name(). */ -function blog_node_name($node) { +function blog_node_name() { return t('personal blog entry'); } Index: modules/blogapi.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blogapi.module,v retrieving revision 1.53 diff -u -F^f -r1.53 blogapi.module --- modules/blogapi.module 25 Aug 2005 21:14:16 -0000 1.53 +++ modules/blogapi.module 27 Aug 2005 11:12:05 -0000 @@ -544,12 +544,8 @@ function blogapi_blogger_title(&$content function blogapi_settings() { $output = form_select(t('XML-RPC Engine'), 'blogapi_engine', variable_get('blogapi_engine', 0), array(0 => 'Blogger', 1 => 'MetaWeblog', 2 => 'Movabletype'), t('RSD or Really-Simple-Discovery is a mechanism which allows external blogger tools to discover the APIs they can use to interact with Drupal. Here you can set the preferred method for blogger tools to interact with your site. The common XML-RPC engines are Blogger, MetaWeblog and Movabletype. If you are not sure which is the correct setting, choose Blogger.')); - foreach (node_list() as $type => $module) { - $node_types[$type] = node_invoke($type, 'node_name'); - if (in_array($type, array('blog'))) { - $defaults[] = $type; - } - } + $node_types = node_list(); + $defaults = isset($node_types['blog']) ? array('blog') : array(); $output .= form_checkboxes(t('Blog types'), "blogapi_node_types", variable_get('blogapi_node_types', $defaults), $node_types, t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).'), 0, 1); return $output; } @@ -716,7 +712,7 @@ function _blogapi_blogid($id) { function _blogapi_get_node_types() { $available_types = variable_get('blogapi_node_types', array('blog')); $types = array(); - foreach (node_list() as $type => $module) { + foreach (node_list() as $type => $name) { if (node_access('create', $type) && in_array($type, $available_types)) { $types[] = $type; } Index: modules/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book.module,v retrieving revision 1.311 diff -u -F^f -r1.311 book.module --- modules/book.module 25 Aug 2005 21:14:16 -0000 1.311 +++ modules/book.module 27 Aug 2005 11:12:06 -0000 @@ -9,7 +9,7 @@ /** * Implementation of hook_node_name(). */ -function book_node_name($node) { +function book_node_name() { return t('book page'); } Index: modules/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum.module,v retrieving revision 1.262 diff -u -F^f -r1.262 forum.module --- modules/forum.module 25 Aug 2005 21:14:16 -0000 1.262 +++ modules/forum.module 27 Aug 2005 11:12:06 -0000 @@ -29,7 +29,7 @@ function forum_help($section) { /** * Implementation of hook_node_name(). */ -function forum_node_name($node) { +function forum_node_name() { return t('forum topic'); } 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 11:12:07 -0000 @@ -32,8 +32,8 @@ function node_help($section) {
Published
When using Drupal's moderation system a node remains unpublished -- unavailable to non-moderators -- until it is marked Published.

Now that you know what is in a node, here are some of the types of nodes available.

", array("%teaser" => url("admin/node/configure/settings"))); - foreach (node_list() as $type => $module) { - $output .= '

'. t('Node type: %module', array('%module' => node_invoke($type, 'node_name'))). '

'; + foreach (node_list() as $type => $name) { + $output .= '

'. t('Node type: %name', array('%name' => $name)). '

'; $output .= implode("\n", module_invoke_all('help', 'node/add#'. $type)); } @@ -203,54 +203,89 @@ 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) { + static $base_names = array(); + 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(); + if (empty($base_names)) { + foreach (module_implements('node_name') as $module) { + $node_names = module_invoke($module, 'node_name'); + if (is_array($node_names)) { + $base = module_invoke($module, 'base_name'); + if (empty($base)) { + $base = array(); + } + foreach ($node_names as $key => $value) { + $base_names[$key] = isset($base[$key]) ? $base[$key] : $module; + } + } + else { + $base_names[$module] = $module; + } + } + } - return $modules[$type]; + return $base_names[$type]; } /** - * Get a list of all the defined node types. + * Get a list of all the defined node types or the human readable name of + * a give type. + * + * @param $node + * Either a node object, a node array, or a string containing the node type. * * @return - * An associate array of consisting of (node type, module name) pairs for all node types. + * For empty $type, an associate array of consisting of + * computer readable node type => human readable name + * pairs for all node types. For a given $type, the human readable name + * for $type. */ -function node_list() { +function node_list($node = '') { 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; - } - } - else { - $types[$module] = $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) { + $types[$key] = $value; } } + else { + $types[$module] = $node_names; + } + } + } + if ($node) { + if (is_array($node)) { + $type = $node['type']; + } + elseif (is_object($node)) { + $type = $node->type; + } + elseif (is_string($node)) { + $type = $node; } } - return $types; + + return $type ? $types[$type] : $types; } /** @@ -264,9 +299,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 +315,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)); } } @@ -575,7 +607,7 @@ function node_search($op = 'search', $ke $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), - 'type' => node_invoke($node, 'node_name'), + 'type' => node_list($node), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, @@ -700,7 +732,7 @@ function node_menu($may_cache) { } else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) { $items[] = array('path' => 'admin/settings/content-types/'. arg(3), - 'title' => t("'%name' content type", array('%name' => node_invoke(arg(3), 'node_name'))), + 'title' => t("'%name' content type", array('%name' => node_list(arg(3)))), 'type' => MENU_CALLBACK); } } @@ -786,7 +818,7 @@ function node_admin_nodes() { */ $node_types = drupal_map_assoc(array_keys(node_list())); foreach ($node_types as $k => $v) { - $node_types[$k] = node_invoke($v, 'node_name'); + $node_types[$k] = node_list($v); } // Regular filters $filters = array( @@ -912,7 +944,7 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), - node_invoke($node, 'node_name'), + node_list($node), theme('username', $node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination)); @@ -947,8 +979,8 @@ function node_types_configure($type = NU $node = new stdClass(); $node->type = $type; - $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_invoke($type, 'node_name')))); - $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_invoke($type, 'node_name')))); + $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_list($type)))); + $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_list($type)))); $output = form_group(t('Submission form'), $group); $output .= form_group(t('Workflow'), implode('', node_invoke_nodeapi($node, 'settings'))); @@ -958,8 +990,8 @@ function node_types_configure($type = NU $header = array(t('Type'), t('Operations')); $rows = array(); - foreach (node_list() as $type => $module) { - $rows[] = array(node_invoke($type, 'node_name'), l(t('configure'), 'admin/settings/content-types/'. $type)); + foreach (node_list() as $type => $name) { + $rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type)); } return theme('table', $header, $rows); @@ -1190,7 +1222,7 @@ function node_validate($node) { // Make sure the body has the minimum number of words. // todo use a better word counting algorithm that will work in other languages if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) { - form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_invoke($node->type, 'node_name')))); + form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_list($node)))); } // Auto-generate the teaser, but only if it hasn't been set (e.g. by a @@ -1279,7 +1311,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); @@ -1403,15 +1435,15 @@ function node_add($type) { } } $output = node_form($node); - drupal_set_title(t('Submit %name', array('%name' => node_invoke($node, 'node_name')))); + drupal_set_title(t('Submit %name', array('%name' => node_list($node)))); } else { // If no (valid) node type has been provided, display a node type overview. - foreach (node_list() as $type => $module) { + foreach (node_list() as $type => $name) { if (node_access('create', $type)) { - $out = '
'. l(node_invoke($type, 'node_name'), "node/add/$type", array('title' => t('Add a new %s.', array('%s' => node_invoke($type, 'node_name'))))) .'
'; + $out = '
'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'
'; $out .= '
'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'
'; - $item[node_invoke($type, 'node_name')] = $out; + $item[$name] = $out; } } @@ -1485,8 +1517,7 @@ function node_preview($node) { $output .= node_form($node); - $name = node_invoke($node, 'node_name'); - drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type))); + drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_list($node))), 'node/add/'. $node->type))); return $output; } @@ -1543,7 +1574,7 @@ function node_submit(&$node) { if (node_access('update', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); - $msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('The %post was updated.', array ('%post' => node_list($node))); } } else { @@ -1552,7 +1583,7 @@ function node_submit(&$node) { if (node_access('create', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); - $msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('Your %post was created.', array ('%post' => node_list($node))); } } @@ -1865,7 +1896,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; } Index: modules/page.module =================================================================== RCS file: /cvs/drupal/drupal/modules/page.module,v retrieving revision 1.133 diff -u -F^f -r1.133 page.module --- modules/page.module 25 Aug 2005 21:14:16 -0000 1.133 +++ modules/page.module 27 Aug 2005 11:12:07 -0000 @@ -28,7 +28,7 @@ function page_perm() { /** * Implementation of hook_node_name(). */ -function page_node_name($node) { +function page_node_name() { return t('page'); } Index: modules/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll.module,v retrieving revision 1.167 diff -u -F^f -r1.167 poll.module --- modules/poll.module 25 Aug 2005 21:14:17 -0000 1.167 +++ modules/poll.module 27 Aug 2005 11:12:08 -0000 @@ -260,7 +260,7 @@ function poll_load($node) { /** * Implementation of hook_node_name(). */ -function poll_node_name($node) { +function poll_node_name() { return t("poll"); } Index: modules/story.module =================================================================== RCS file: /cvs/drupal/drupal/modules/story.module,v retrieving revision 1.168 diff -u -F^f -r1.168 story.module --- modules/story.module 25 Aug 2005 21:14:17 -0000 1.168 +++ modules/story.module 27 Aug 2005 11:12:08 -0000 @@ -21,7 +21,7 @@ function story_help($section) { /** * Implementation of hook_node_name(). */ -function story_node_name($node) { +function story_node_name() { return t('story'); } Index: modules/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system.module,v retrieving revision 1.227 diff -u -F^f -r1.227 system.module --- modules/system.module 25 Aug 2005 21:14:17 -0000 1.227 +++ modules/system.module 27 Aug 2005 11:12:08 -0000 @@ -793,8 +793,8 @@ function system_theme_settings($key = '' $node_list = module_invoke('node', 'list'); if ($node_list) { $group = ''; - foreach ($node_list as $type => $module) { - $group .= form_checkbox(node_invoke($type, 'node_name'), "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); + foreach ($node_list as $type => $name) { + $group .= form_checkbox($name, "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); } $form .= form_group(t('Display post information on'), $group, t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type')); } Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.219 diff -u -F^f -r1.219 taxonomy.module --- modules/taxonomy.module 25 Aug 2005 21:14:17 -0000 1.219 +++ modules/taxonomy.module 27 Aug 2005 11:12:09 -0000 @@ -107,17 +107,12 @@ function taxonomy_menu($may_cache) { } function taxonomy_form_vocabulary($edit = array()) { - foreach (node_list() as $type => $module) { - $node_type = node_invoke($type, 'node_name'); - $nodes[$type] = $node_type ? $node_type : $type; - } - $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE); // Prepend extra vocabulary form elements. $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit)); $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.')); $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.')); - $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], $nodes, t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); + $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_list(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows a tree-like hierarchy between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows related terms in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.'));