Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
node system
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
31 Jan 2009 at 17:01 UTC
Updated:
3 Jan 2014 at 00:07 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
moshe weitzman commentedComment #2
AmrMostafa commentedI traced it back to this issue #339929: Move node links into $node->content
Do we still need this hook at all?
I think that the proper way to do hook_node_alter()-like in the current system is using
hook_preprocess_node:Does that sound right?
We would need docs for that and more importantly a patch for
node_feed(but I believe that needs its own issue).Comment #3
avpadernohook_preprocess_node()seems to be thought for themes, whilehook_DATA-ID_alter()seems for modules.It's also true that some modules implement
hook_preprocess_node()(or similar hooks), but they normally implement it to change the way something is rendered in the current theme.Comment #4
Anonymous (not verified) commented@yched: Don't you mean hook_node_alter? I couldn't find hook_nodeapi_alter in the documentation or the functions you mention.
@Kiam: I also find no hook_preprocess_node but I find template_preprocess_node, is that what you meant?
Comment #5
avpadernoA module can define a function called
<module_name>_preprocess_node(), and that function would be used the same.There are two modules that use a
<module_name>_preprocess_<section_to_render>(), with the purpose of changing what it shown in a theme template; one of the modules changes the page title used inside the<head>tag (to say the true, the module defines<module_name>_preprocess_page().What I mean is that the mentioned hooks have different purposes, and uses.
Comment #6
jhodgdonThis has already been discussed quite a bit here http://drupal.org/node/390774, and a patch there fixes up the doc to address these questions.
So I'm marking this as a duplicate.
Comment #7
AmrMostafa commentedThis is not a documentation issue. The issue you refer to is merely concerned about docs, what we are trying to solve here is whether this hook is still needed or should be removed all together.
Comment #8
Anonymous (not verified) commentedAnd it is specific to hook_node_alter and not any other hook_${type}_alter function.
Comment #9
yched commentedhook_nodeapi_* were renamed to hook_node_* since the OP :-)
Comment #10
webchickIt's definitely silly for there to be two ways to alter the content of a node; one for RSS feeds and one for regular operations.
Is changing the line in Moshe's #1 from node_build to node the only thing required?
Comment #11
AmrMostafa commented@webchick actually I believe this is a bug in node_feed(), it's effectively broken. I worked on this today at #449718: node_feed() is using the old node building API
Comment #12
yched commentedThe patch committed in #449718: node_feed() is using the old node building API effectively got rid of the last invocation of hook_node_alter().
I don't know if the previous need for hook_node_alter() is now fully undertaken by some other new hook (hook_node_alter always confused me a little), but if so we should remove it from node.api.php :
Comment #13
Anonymous (not verified) commentedMy question would be how many modules port(ed|ing) to D6 use it? What other API could be used to achieve the same action?
Comment #14
brianV commentedJust spoke to catch on IRC about this, and he suggested that if it is still popular in contrib modules, it probably isn't worth killing it off. Is anyone able to grep the contrib archive?
Comment #15
AmrMostafa commentedI've went ahead and grepped/awked the contrib repos. Results follow..
25 modules use it.
Many of these modules use hook_node_alter() because they would rather wait after all modules, not because they want to process the rendered node. Those modules will be much happier/better with D7's hook_node_build_alter(), and so the real usage of this hook is actually much less than 25.
Comment #16
bengtan commentedHi,
Thanks alienbrain for notifying me about this. I'm the maintainer of composite.module.
composite.module only uses 'hook_nodeapi: alter' in D6.x because it waits for other modules to inject their content through 'hook_nodeapi: view'. If there is another way to do this in D7 (ie. maybe hook_node_build_alter() as mentioned in the preceding comment), then composite.module will not need to use hook_node_alter().
However, I can't find any reference to hook_node_build_alter() on http://api.drupal.org/api/group/hooks/7. I presume it just hasn't been documented yet?
Comment #17
bengtan commentedJust had a thought about a compromise approach if the situation about contrib modules is uncertain.
You could remove hook_node_alter() from D7, but do it in such a way that a D7-only contrib module (ie. hook_node_alter.module ) is written that adds this hook back in.
Then, if any contrib modules need hook_node_alter() in D7, they are marked as having a dependency on hook_node_alter.module.
Make the description of hook_node_alter.module clearly state that hook_node_alter() is deprecated and will be removed in D8.
[EDIT]
And/or, if sometime in the future, the usage stats of hook_node_alter.module drops down to zero, you can safely remove hook_node_alter(). Well, maybe.
Comment #18
AmrMostafa commentedThanks for dropping by :)
Regarding #16, the hook definitely exists. It's not in http://api.drupal.org/api/group/hooks/7 but that's a documentation issue. I will try to quickly summarize the changes you need to be aware of.
In D6, "alter" was available as a way for module authors to work on the rendered node, that is, the final HTML of the node. Some modules also used it when they wanted to make sure that other modules have finished adding their additions to $node->content. In D7, "alter" was replaced by hook_node_build_alter(). However, it was also decided that the node should stay un-rendered (i.e. stay as a FAPI structure in $node->content) as long as possible. So while "alter" received a rendered node, hook_node_build_alter() operates on the same unrendered $node object (the same as in "view" hook"). Generally, that's much more flexible, unless you really want to operate on the final HTML. In that case, it was suggested that modules could use hook_preprocess_node(), which allows operating on the rendered node content.
It appears to me that for your case, hook_node_build_alter() definitely covers your need.
Regarding #17, I don't think we are that desperate :) I'm pretty sure what we currently cover "alter" pretty good. I've skimmed through most modules above and made sure they can do what they do using the new hooks, the ones I wasn't sure of, I e-mailed their authors asking for feedback.
Comment #19
moshe weitzman commentedDon't forget that there is #post_render and preprocess_node where modules can fiddle with fully rendered HTML.
Comment #20
AmrMostafa commentedHere is the patch we need. Removes docs for hook_node_alter() and adds docs for hook_node_build_alter().
Inspired by #19, in the sample implementation for hook_node_build_alter() I added an example of using #post_render to act on the rendered HTML.
Comment #21
moshe weitzman commented$node->content['#post_render'] = array('my_module_node_post_render');> should be$node->content['#post_render'][] = 'my_module_node_post_render';so as to not blow away other #post_render callbacks that might have been added.Thanks for the nice docs.
Comment #22
AmrMostafa commentedThanks for the review, updated patch attached.
Comment #23
moshe weitzman commentedComment #24
catchVery nice.
Comment #25
dries commentedLooks good. Committed to CVS HEAD. Thanks!
Comment #26
AmrMostafa commentedI managed to include a funny syntax error, very tiny patch attached. Thanks to Berdir for reporting this.
Comment #27
cburschkaThis syntax error has already made PIFR reject at least one patch due to a broken head... best fix this ASAP.
Comment #28
webchickCommitted follow-up.