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

neRok’s picture

Status: Active » Closed (won't fix)

There 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))) {

joachim’s picture

Status: Closed (won't fix) » Active

Sorry, but having to use arg() is a terrible hack!

neRok’s picture

if ($node = menu_get_object()) {
 $nid = $node->nid;
}

Its 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.

joachim’s picture

Status: Active » Closed (won't fix)

Ah, I didn't think of menu_get_object()! Ok, closing then. I'll add a comment to the docs for hook_node_view().