Closed (fixed)
Project:
Drupal core
Version:
x.y.z
Component:
node system
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
23 Aug 2006 at 15:25 UTC
Updated:
17 Nov 2006 at 16:15 UTC
Jump to comment: Most recent file
In response to pwolanin's post on the devel mailing list about node types, we should introduce a new hook_node_type(), which will allow modules to react to node types being created / updated / deleted. This hook would work very much like hook_user() and other similar hooks.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | hook_node_type.patch | 4.93 KB | Jaza |
Comments
Comment #1
pwolanin commentedFor this hook to be reliable invoked, it would seem that any node type creation/deletion needs to be done through a function call rather than through any direct insert into the DB. The system.install file seems to do it two different ways for install vs. update. However, what I find a little odd is that the function node_type_save() is not used in either, and also that this function doesn't include the calls below (from system.install), in a fashion similar to node_save() calling cache_clear_all() at the end.
Comment #2
karens commented+1 on the idea of creating this hook.
See an issue at http://drupal.org/project/comments/add/90497 that shows one place the hook would be useful - to keep the vocabulary_node_types table up to date when content types are deleted. Right now the node module has no hook to allow the taxonomy module to act, and the taxonomy module has no hook that would allow the node module to act. It makes some sense to me for the node module to provide a hook when content types change and for the taxonomy module to take responsibility for keeping its own table up to date by using that hook.
Comment #3
pwolanin commentedmarking as critical- 5.x shouldn't go to RC without a fix for this problem. Either we need a well-implemented hook of the type suggested, or the ability to change to type names needs to be disabled (per http://drupal.org/node/85062). I'm trying to update one of my modules (node_clone) for 5.x now, and want to help update the event module. Both of these (as well as the core taxonomy module) save settings based on the node type. If the type name changes, all the setting are lost and the site breaks.
Comment #4
Jaza commentedAttached patch does the following:
hook_node_type()in thenode_type_save()function, for insert and update of node types.node_type_form_submit()- the new approach is much better, as it allows for node types to be saved programatically, without submitting a form, and for these actions to still take place when the hook fires).The hook needs to be invoked and implemented for 'delete' as well, but this belongs in a separate patch - see http://drupal.org/node/83202 - it will go here. This patch is ready for review, and is hopefully still able to go in for Drupal 5.
Comment #5
karens commentedThis looks good to me except that I don't see how this will answer my original problem -- how do you get the taxonomy module to remove a deleted node type from the vocabulary_node_types table? Your hook won't do it and your separate patch won't do it either.
I definitely would like to see this go into 5.0 though. It will be needed by CCK, too, since CCK is managing tables and caches that need to be updated when content types change. In 4.7 CCK can tell when content type changes happen and react to them, in 5.0 it cannot.
Comment #6
karens commentedI closed the issue about the taxonomy not updating the vocabulary_node_types table at http://drupal.org/node/90497 and redirected the discussion over here, since this patch is the best way to solve that problem (at least it will be if some provision for handling content type deletions is provided).
Comment #7
drummCommitted to HEAD, with a slight modification to the node.module changes for simpler code.
Comment #8
Jaza commentedUpdated the developer docs (that link isn't working yet, but it should work soon) and the module upgrade docs.
Comment #9
AmrMostafa commentedSorry, but the 'Changed association...' message isn't t()-ed.
Actually, I think this message should be removed, users already expect things to work together :-).
And if it's not, then we will also need to print a similiar message in similiar cases, like http://drupal.org/node/85062. the messages list can be long this way.
Comment #10
AmrMostafa commentedapologies, completely forgot about format_plural. I still think the message should be removed though :-).
Comment #11
(not verified) commented