template_preprocessor_node() does $variables['page'] = (bool)menu_get_object();
That's not specific enough, it doesn't test "are we on *this node's* page"?

Forbids embedding nodes within nodes - see #658150-3: Nodereference D7 port.

Comments

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new729 bytes

Here is a first patch, i think this still needs a test.

yched’s picture

Thanks for being so quick !

This should do the trick, although I'm not sure why we need a strict comparison instead of a regular ==.

Not sure of the best way to test this either. Building a test module that uses page_alters to append a given node into the page of another node ?

dawehner’s picture

I tested it with eval php in a node body, but i'm sure your way is better :)

I used === because 1. its faster, 2. drupal should return the same database always, but i don't have a special reason why i chosed this.

moshe weitzman’s picture

I think we need this check in a couple module places. Lets put this check in own function like node_is_detail_page() or somesuch. Perhaps you can find similar cases by grep for menu_get_object().

dawehner’s picture

StatusFileSize
new3.61 KB

Here is new version, which fixes on every(i hope) place.

dries’s picture

Patch looks good to me, but it would be nice to have yched confirm that it would enable progress in #658150-3: Nodereference D7 port.

moshe weitzman’s picture

Status: Needs review » Needs work

I think this would be a bit clearer in node_is_detail_page():

return isset($page_node->nid)) && $page_node->nid === $node->nid

I agree that === is non standard and should be removed until we require type consistency in other places as well.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.6 KB

Here it is

yched’s picture

Status: Needs review » Needs work

I confirm that the patch fixes the bug in #658150-3: Nodereference D7 port.

+++ modules/node/node.module
@@ -1323,6 +1323,19 @@ function node_show($node, $message = FALSE) {
 /**
+ * Checks whether a certain node is shown on the current page.
+ *
+ * @param $node
+ *   A node object.
+ * @return
+ *   Is the node shown on the current page.
+ */
+function node_is_detail_page($node) {

That could be more specific. A node is "shown" in the frontpage listing too.

I'm also not sure that 'detail_page' is the right terminology for a node's node/%nid page. Then again, I'm not sure what the correct terminology would be, if we have any in core currently.
This is nitpick, I'm fine with the function name if moshe and Dries are OK with it.

Will set to RTBC once the PHPdoc is updtated.

This review is powered by Dreditor.

dawehner’s picture

What about node_is_own_pager?

dawehner’s picture

I wanted to say "node_is_own_page"

dries’s picture

Status: Needs work » Needs review

Let's stick with detail_page and fix the phpDoc.

damien tournoud’s picture

This is actually a duplicate of #445902: (bool) menu_get_object() is *not* an equivalent of $page, but I'll kill the other one instead.

One thing I don't really understand: why do we need that at all? Isn't that something that build modes should cover completely? Why do we need to make a difference between "A node displayed on a node/xxx page by itself" and "A full node displayed somewhere"?

damien tournoud’s picture

Reading #658150-3: Nodereference D7 port, I understand why we need that. Shouldn't we refactor the node template file? We could have:

- node.tpl.php: the node without its title
- node-wrapper.tpl.php: a wrapper with the title

I don't really understand why we removed the $page parameter. After all, it *was* useful.

sun’s picture

+++ modules/node/node.module
@@ -1323,6 +1323,19 @@ function node_show($node, $message = FALSE) {
+function node_is_detail_page($node) {

Why not node_is_full_page() ?

Or if the consideration was that this clashes too much with the build mode, then why not even

node_is_page() ?

I'm on crack. Are you, too?

bleen’s picture

+1 for node_is_page()

dries’s picture

+1 for node_is_page() here too

dawehner’s picture

StatusFileSize
new3.56 KB

new version

yched’s picture

remark about PHPdoc in #9 still applies. Other than that, RTBC.

dries’s picture

Let's update the documentation, and get this committed! :)

bleen’s picture

StatusFileSize
new4.76 KB

how bout this

aidanlis’s picture

An aside, I don't like "I agree that === is non standard". As the author pointed out, it is significantly faster as it avoids running PHP's typecasting comparison. It really should be used by default, and avoids all sorts of nasty bugs like 0 == 'foo'.

sun’s picture

+++ modules/node/node.module	16 Dec 2009 15:05:10 -0000
@@ -1323,6 +1323,20 @@ function node_show($node, $message = FAL
+ * Checks if the current page is displaying this sepcific node's 
+ * full view (ex. node/%nid) as opposed to its teaser.

PHPDoc summary should be on one line. Either shorten this or split it into a short summary and a separate description.

+++ modules/node/node.module	16 Dec 2009 15:05:10 -0000
@@ -1323,6 +1323,20 @@ function node_show($node, $message = FAL
+function node_is_page($node) {
+  $page_node = menu_get_object();
+  return (isset($page_node->nid)) ? $page_node->nid == $node->nid : FALSE;

I don't really see how $page_node->nid could ever not be set if there is a $page_node. menu_get_object() can, however, return NULL or FALSE. Thus, I'd suggest to change the first condition to !empty($page_node).

This review is powered by Dreditor.

bleen’s picture

StatusFileSize
new4.72 KB

EDIT: ignore this patch ... forgot the "!"

bleen’s picture

StatusFileSize
new4.72 KB

use this patch instead of #24

sun’s picture

+++ modules/node/node.module	16 Dec 2009 18:41:24 -0000
@@ -1323,6 +1323,19 @@ function node_show($node, $message = FAL
+ * Check if the current page displays this sepcific node's full view (ex. node/%nid).
...
+ * @return
+ *   Is the current page displaying the full view of this specific node.

Typo in 'specific'... Also, 'this' is missing its context here.

However, since this is a simple helper function, we want to consolidate @return into the PHPDoc summary and remove @return.

"Returns whether the current page is the full page view of the passed in node."

+++ modules/node/node.module	16 Dec 2009 18:41:24 -0000
@@ -1323,6 +1323,19 @@ function node_show($node, $message = FAL
+  return (!empty($page_node)) ? $page_node->nid == $node->nid : FALSE;

We either want to drop the additional parenthesis around !empty() or wrap the entire ternary operator condition. The latter is preferred, because it clarifies where the condition starts and ends, and what is going to be returned.

I'm on crack. Are you, too?

bleen’s picture

StatusFileSize
new4.63 KB
sun’s picture

Status: Needs review » Reviewed & tested by the community

Great - thank you

dries’s picture

Status: Reviewed & tested by the community » Fixed

I agree that this is great. Plus, it unblocks the work on nodereference. Committed to CVS HEAD.

damien tournoud’s picture

Status: Fixed » Needs work
+function node_is_page($node) {
+  $page_node = menu_get_object();
+  return (empty($page_node) ? $page_node->nid == $node->nid : FALSE);
+}

Hm.

dries’s picture

Status: Needs work » Needs review

I rolled back the patch. That empty() should probably be !empty().

bleen’s picture

StatusFileSize
new4.63 KB

blarrg!! Sorry about that.

Status: Needs review » Needs work

The last submitted patch failed testing.

bleen’s picture

Status: Needs work » Needs review

I beg to differ, testbot.

bleen18 requested that failed test be re-tested.

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

damien tournoud’s picture

Status: Fixed » Active

We have one test failure that is probably related to this patch:

Node preview title is equal to node title.  Node  node.test  1146  NodeTitleTestCase->testNodeTitle()  Fail
cburschka’s picture

Status: Active » Fixed

I have traced that failure back to #654854: Clean up conditions in comment_reply(), avoid node_view() when unnecessary., actually. Aside from the chronology, there is also a clear reason for why that patch causes the failure (node is not displayed on comment reply page). So this issue is innocent.

Status: Fixed » Closed (fixed)

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

gábor hojtsy’s picture

Unfortunately this resulted in the critical issue that the same node now cannot be displayed in multiple build modes on its own page. Eg. a node cannot appear in both a summary/teaser block and its own full page at the same time. Both will render the full page: #721754: A node cannot be displayed in different view mode on its own page.