A basic node (nid "123") exists and a module registered two paths using hook_menu
:
first/%node
second
Both page callbacks use node_page_view($node)
to display a fullpage view of the node, except the second callback additionally uses node_load(123)
to get a reference to $node
.
Therefore http://localhost/first/123
and http://localhost/second
look the same as far as the user is concerned.
However hook_preprocess_page
receives the node
variable only with the first path, therefore Drupal obviously does something beyond node_load
when it sees a %node
wildcard, any idea what it is so that hook_preprocess_page
receives the reference to $node
in both cases ? (because handling everything internally in the second path produces much more friendly urls than redirecting to the first path from the second).
Example:
<?php
/**
* Implementation of hook_preprocess_page().
*/
function mymodule_preprocess_page(&$vars){
if (@isset($vars['node'])) echo '<h1>[mymodule.module] Node is defined</h1>';
else echo '<h1>[mymodule.module] Node is NOT defined</h1>';
}
/**
* Implementation of hook_menu().
*/
function mymodule_menu(){
return array(
'first/%node' => array(
'title' => 'First callback',
'page callback' => 'mymodule_page_first',
'page arguments' => array(1),
'access callback' => TRUE,
),
'second' => array(
'title' => 'Second callback',
'page callback' => 'mymodule_page_second',
'access callback' => TRUE,
),
);
}
/**
* Page callback for url "http://localhost/first/123".
*/
function mymodule_page_first($node){
echo '<h1>[mymodule.module] Function mymodule_page_first</h1><pre>';
var_dump($node);
echo '</pre>';
return node_page_view($node);
}
/**
* Page callback for url "http://localhost/second".
*/
function mymodule_page_second(){
$node = node_load(123); //the ID of an existing node
echo '<h1>[mymodule.module] Function mymodule_page_second</h1><pre>';
var_dump($node);
echo '</pre>';
return node_page_view($node);
}
(Source of file mymodule.module
)
My best/only hope so far is to dig in the source of node_page_view
and all functions it consequently triggers until I find what happens between the moment node_page_view
is called and the moment the module_invoke_all
which triggers the hook is called.