Steps to reproduce:
1. Create a block that displays nodes, and set the build mode (a.k.a. view mode) to show full nodes.
2. Enable the block.
3. Visit node/XYZ, where XYZ is one of the nodes that is also being displayed in the block.

Inside the block, you'll see node #XYZ all messed up - it will be missing its title, have the comment form displayed underneath it, and other nasty things.

This could arguably be considered a Drupal core bug (see, for example, some of the discussion at #721754: A node cannot be displayed in different view mode on its own page) but it's not clear what the solution in core is. Anyway, it makes sense to have an issue for it here for now, since the bug is certainly most noticeable in Views.

One possibility to deal with this would be for Views to accept the idea that the 'full' view mode provided by Drupal core is reserved for special use as the "this is the only node on the page scenario" (similar to the way the $page parameter of node_view() worked in Drupal 6), and therefore not provide it as an option to use inside a view.

But this is somewhat unfortunate, since people do sometimes want to create views of what they would consider to be "full posts", so by denying access to the 'full' mode we'd be requiring people who want that to go off and create their own custom view mode that more or less does the same thing but isn't actually called 'full'.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

There's at least one other issue in core about this, though this one is by far the most detailed so I'm tempted to say to mark others a dup of this.

However, I think it's true for more than just the 'full' view. In the past (like, Drupal 4.7 past) we had problems with this because node_view() can be destructive to the $node object. I suspect that is what's happening in this case as well. It may be worse, though, because if it's destructive to the $node object that is cached, then you're *really* screwed.

David_Rothstein’s picture

If there's an issue with node_view() being destructive to the node object, that might actually be a different problem.

But the issue I'm thinking of comes just from the code logic. For example, the reason the node is missing its title when it's displayed in the block is that template_preprocess_node() has this code:

 $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);

(and then $page is later used in node.tpl.php to decide whether or not to print the node's title).

The problem is that when we are at node/XYZ, node_is_page() will return TRUE whenever that node is passed in. So even when the node is being rendered inside the block, the above logic sets $variables['page'] to TRUE, and the title doesn't get printed.

And there are a few other places in the node_view() workflow that use the same kind of logic.

merlinofchaos’s picture

I guess that really means that it's just not safe to use the 'full' mode in blocks. Hmm.

dawehner’s picture

So what about hiding the full build mode for block displays and display a additional help in the formula?

merlinofchaos’s picture

That's a solution. It might be the best solution, but will think on it.

dawehner’s picture

One problem is that you often have a value in the default display, which is not overriden currently. You can't disable the formular element there, because you wouldn't be able to change it on a page display for example..

mh.....

merlinofchaos’s picture

Status: Active » Fixed

Committed a fix that is able to detect this condition and attempts to set/unset variables to work around it. Seems to work properly in my tests, though we can't guarantee contrib won't ignore the settings.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joshmiller’s picture

Status: Closed (fixed) » Needs review
FileSize
589 bytes
2.86 KB
174.66 KB

Coming from here #1194614: Comments do not render in a View of content. and have now confirmed (see screenshot or use attached view export on a standard install with a few articles) that this if statement no longer causes errors, even when viewing the node and a block with a view with a node. Probably related to Drupal 7's radical page rendering changes.

In short, this is no longer needed and, in fact, causes a problem for someone wanting the entire node (comments and all) to be rendered in a block.

Patch is attached, review and commit is requested :)

Not causing an error.

FreeAndEasy’s picture

This works for me, I just excluded the current node in the view via:
contextual-filter>nid>provide-default=content-id-from-url>exclude

Please commit this patch, not having comments on full-view-node views is worse than getting it jumbled up when displaying node and full-node-view on one page.

heyyo’s picture

Works great for me too.

vistree’s picture

Hi, is it possible to implement this patch as a hook inside template.php
(so no need to patch a core file each times we update drupal ...)

I tried the following which does not work:

function MYTHEMENAME_row_node_view_preprocess_node(&$vars) {
  $node = $vars['node'];
  $options = $vars['view']->style_plugin->row_plugin->options;

  // Prevent the comment form from showing up if this is not a page display.
  if ($vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) {
    $node->comment = TRUE;
  }

  if (!$options['links']) {
    unset($vars['content']['links']);
  }

  if (!empty($options['comments']) && user_access('access comments') && $node->comment) {
    $vars['content']['comments'] = comment_node_page_additions($node);
  }
}
vistree’s picture

By the way: why isn't this in Views core? Anybody can disable the comment view in a block by disabling the "Show comments" checkbox?!

rooby’s picture

If I understand this issue correctly then #1574806: Rendering node views on node page can cause $page in node.tpl.php to be FALSE when it should be TRUE may be a duplicate.

There is a patch there that fixes the issue for me.

The patch in #9 seems off topic as it is specific to comments whereas this issue is not.

Chris Matthews’s picture

The 6 year old patch in #9 to node.views.inc still applies cleanly to the latest views 7.x-3.x-dev, but as rooby said in #14:

The patch in #9 seems off topic as it is specific to comments whereas this issue is not.