[drupal-devel] [bug] Multiple node types are broken

chx drupal-devel at drupal.org
Sat Aug 27 09:26:08 UTC 2005


Issue status update for 
http://drupal.org/node/29785
Post a follow up: 
http://drupal.org/project/comments/add/29785

 Project:      Drupal
 Version:      cvs
 Component:    node system
 Category:     bug reports
 Priority:     critical
 Assigned to:  chx
 Reported by:  chx
 Updated by:   chx
 Status:       patch (code needs review)
 Attachment:   http://drupal.org/files/issues/node_basename_0.patch (16.81 KB)

I thought a bit more on the issue and created something which I think is
a very clean solution. What do we need? We need a capability to get
human readable names for node names. Also, we need occasionly a
capatibility to override 'module' as the base for 'hook_foo'. Well,
then let's define hook_node_name and hook_base_name for these purposes.


hook_node_name returns either a string or an array eg. 'somemodule-1'
=> t('this is a content type');. 


If you want to use different base name, define them in hook_base_name
eg. 'somemodule-1' => 'somemodule_text' and then 'somemodule_text_load'
will be called. If you have only one node type per module ie. you
returned a string in hook_node_name then hook_base_name is not even
called, there is no reason.


Now node_list('somemodule-1') would return t('this is a content
type');. Also, node_list() as it stands is pretty useable in itself as
you'll see in the code, it elinimates a few lines of code here and
there.


The change of node_get_module_name to node_get_base_name affects only
group and og module in contrib and as for current node type modules the
output is the same (because noone has hook_base_name atm) a simple
replace will do as upgrade.




chx



Previous comments:
------------------------------------------------------------------------

Sat, 27 Aug 2005 08:31:11 +0000 : chx

Attachment: http://drupal.org/files/issues/node_basename.patch (3.92 KB)

People come and tell me that I have broken node_get_module_name. I tell
them I fixed it. This leads nowhere. Yesterday Kjartan, jakeg and me
had finally a conversation during which we have arrived to the
conclusion that there is no need for two hooks and hook_node_name could
return either a string or an array in the form of:



<?php
array('type-a' => array('node type a', 'base')), 'type-b' => 'node type b', 'node type c');
?>




Which would define a 'type-a' , with a human readable name 'node type
a' and base_load would be called for hook_load and so forth. for
'type-b' , the difference is that modulename_load would be called. For
'node type c', the node type would be modulename.




------------------------------------------------------------------------

Sat, 27 Aug 2005 08:53:15 +0000 : jakeg

+1


Except on third example surely their shouldn't be spaces in 'node type
c' as surely that won't work?


Just to make it clear to people: this patch enables a module, such as
project.module, to define more than one node type, using different
hooks for each of those node types within the same module. Otherwise,
functions would have to be shared between the node types defined by the
function, or a different module would be needed for each node type.
Neither of which are desirable.




------------------------------------------------------------------------

Sat, 27 Aug 2005 09:20:08 +0000 : jakeg

Currently gives warnings such as:


Warning: Missing argument 1 for page_node_name() in ...something.module
on line x


Perhaps add argument $null = '' or something similar for backwards
compatability as e.g. page.module calls as thus:


function page_node_name($node) {
  return t('page');
}


... so we need the $node argument to be allowed, even if its totally
pointless.







More information about the drupal-devel mailing list