Closed (won't fix)
Project:
Drupal core
Version:
7.x-dev
Component:
node.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Mar 2012 at 11:09 UTC
Updated:
6 Jun 2013 at 06:14 UTC
In D6 node_view had the $page parameter:
> $page: Whether the node is being displayed by itself as a page.
This was passed down to various ops in hook_nodeapi().
On D7 we have view modes which are more powerful, but we've lost this crucial bit of context.
So a module that is implementing a node API hook, say hook_node_view(), can't know whether the node is being displayed as part of a list or as a standalone page, since any display mode can be used in any context.
Example bug: #1480238: "This is a newsletter edititon." message shows when the node is listed on the front page.
Comments
Comment #1
neRok commentedThere are many ways to get some 'context'.
hook_node_view($node, $view_mode, $langcode) passes the view mode, for one.
You can also implement something along the lines of
if (arg(0) == 'node' && is_numeric(arg(1))) {Comment #2
joachim commentedSorry, but having to use arg() is a terrible hack!
Comment #3
neRok commentedIts not hard to work out if you are or arent on a node page. And you know the display mode, so this should be sufficient.
I cant imagine any other use cases. Say I have a view of nodes and want them to output 'full content', but the module decides to not show something on 'list' pages (as per your example). Well, now Drupal is not outputting what I want, which is a list of nodes full content. If I didnt want the modules output on my list, I would setup a list page view, and the module should allow me disable its content for that page view.
I really think this can be closed.
Comment #4
joachim commentedAh, I didn't think of menu_get_object()! Ok, closing then. I'll add a comment to the docs for hook_node_view().