Rough time trying to alter 'node/[nid]' menu paths. Help needed!

PWG - March 13, 2008 - 11:00

I've spent a loooot of time trying to beat this one but have reached the stage when breaking something valuable seems like the next logical step so I guess I need some assistance.

I've been trying to override the view node path (e.g. 'node/13') for webforms but only *parts* of my changes kick in.

Here's my problem. In the webform module (2.x) in the webform_menu() function there's the following code:

<?php
if ($may_cache) {
...
}
elseif (
arg(0) == 'node' && is_numeric(arg(1))) {
   
$nid = arg(1);
   
$node = node_load($nid);
   
$sid = (arg(2) == 'submission' && is_numeric(arg(3))) ? arg(3) : NULL;

    if (
$node->nid && $node->type == 'webform') {
     
$items[] = array(
       
'path' => 'node/'. $nid,
       
'title' => $node->title, // Set the title for the node menu item.
       
'callback' => 'node_page_view',
       
'callback arguments' => array($node),
       
/** Changed faulty access parameter. used to be 'access' => TRUE, */
       
'access' => node_access('view', $node),
       
'type' => MENU_CALLBACK,

?>

Since I want to override this I have put a similar piece of code in my own module's _menu() function. The only changes are another access parameter and a different callback parameter. Like this:


<?php
      $items
[] = array(
       
'path' => 'node/'. $nid,
       
'callback' => 'wbfsurvey_xxx',
       
'title' => $node->title, // Set the title for the node menu item.
       
'callback arguments' => array($node),
       
/** Changed faulty access parameter. used to be 'access' => TRUE, */
       
'access' => (user_access('create survey') || (wbf_checkit($node))),
       
'type' => MENU_CALLBACK,
      );
?>

In both cases the items are in the !$may_cache section of _menu().

What happens is that *my* access parameter kicks in but whatever I put in as callback parameter does not get called. Furthermore, if I try and change the callback parameter in the webform module that new callback parameter is ignored as well! 'node_page_view' keeps being executed...

I've fiddled around with the module weight. The node module is set to 0, the webform module is set to -1 and my module I set to -10. If I try and set it to say +10 my access parameter is not used anymore. I have Devel installed and have used the reset menus option but to no avail.

What is going on?

Petter

Make sure you get node/x/view

quicksketch - March 13, 2008 - 17:17

While the node/x access needs to be set, make sure you also change the menu entry for node/x/view (it's the *real* callback that gets used). And as you've already done, make sure that your module weight is lower than the module that defines the menu entry you're over riding.

Nathan Haug
creative graphic design        w: quicksketch.org
& software development       e: nate@quicksketch.org

Thanks, quicksketch. I still

PWG - March 13, 2008 - 20:04

Thanks, quicksketch. I still don't get it to work, though. I tried putting the node/x/view item right below node/x in hook_menu() and reset the menu cache (although resetting the menu cache should not be needed since !$may_cache == FALSE). Like this:

<?php
        $items
[] = array(
         
'path' => 'node/'. arg(1) .'/view',
         
'title' => t('View'),
         
'type' => MENU_DEFAULT_LOCAL_TASK,
         
'weight' => -10
       
);
?>

Then I tried changing the title parameter to match the one in the webform module and added the same 'callback' and 'callback arguments' parameters to it as I put into node/x. Like this:

<?php
        $items
[] = array(
         
'path' => 'node/'. arg(1) .'/view',
         
'callback' => 'wbfsurvey_xxx',
         
'title' => $node->title, // Set the title for the node menu item.
         
'callback arguments' => array($node),
         
'type' => MENU_DEFAULT_LOCAL_TASK,
         
'weight' => -10
       
);
?>

Cleared the menu cache again. The tab name changed but still same old callback function gets called and my custom callback function is ignored. What am I missing?

Petter

Anyone?

PWG - March 16, 2008 - 12:49

Anyone?

i also tried but no

Jancis - July 4, 2008 - 15:10

i also tried but no success.. and i have to find solution for this too..

any ideas?

i dont know if this really

Jancis - July 4, 2008 - 22:09

i dont know if this really will solve your problem but it did for me:

put this into installscript:
$weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'webform'"));
db_query("UPDATE {system} SET weight = %d WHERE name = 'mymodule'", $weight + 1);

the path and callback will be taken from your module.

note that you can also change this directly into database in table "system"

Hmm

dmitrig01 - July 4, 2008 - 16:15

How about just altering the node with hook_nodeapi, with $op = 'view'?

You could override all of $node->content and put your custom content in.

Then, you could override the template to jsut print $content and nothing else.

[Drupal++]

 
 

Drupal is a registered trademark of Dries Buytaert.