Project:Node Go To
Version:5.x-2.0
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Token is not working

Comments

#1

My experience has been that only the node tokens and the global tokens are working, but none of the CCK tokens. The reason is that the $node variable in the nodegoto_node_form_submit function is not instantiated.

Proposed fix for update:
Insert at line 47 of version 5.x-2.0 the following code:
$node = node_load($form_values['nid'], NULL, FALSE);

Node_load at this point retrieves the node from memory and not from database, so performance shouldn't suffer.

What I don't know however if the fix above can also be made for insert and delete operations? The nid probably doesn't exist yet on insert, and does it still exist during delete?

Otherwise, the module should document which tokens it supports.

#2

I'm correcting myself: Node tokens aren't working, either. Only global tokens are working - which greatly limits the usefulness of token support.

#3

I am also seeing this behavior. Not having access to the node tokens eliminates our ability to direct users to the appropriate locations after submit, update, and delete.

I would think that you could use the node_nid value from the sequence table to determine what the nid will be for an insert, but I'm not sure how you could access node tokens on delete.

#4

i am experiencing the same problem... how can i redirect to the node after updating?
will there be a fix?

#5

I got a working solution now for updating - now I need to figure out how I can create a patch with the changes. I hope I can post something soon.

#6

same problem here

a patch would be very much appreciated.

it would be great also to have a look at the code just to cut time

thank you!

#7

you could use this:

in admin/settings/nodegoto >> Set the path to redirect for, when UPDATING

choose the right input box (i.e. "Insert the path for Blog entry: ")

and fill it in this way

node/[path-arg-2]/edit

this works for me.

#8

OK, here is the code then; the code below works for insert and for update with token:

Insert this new function in the module to store the node in the session if needed:

<?php
function nodegoto_nodeapi(&$node, $op, $teaser, $page){
 
 
//gm change Sept 13, 2008: save node on insert if it is a node type that has a redirection set
 
if($op === 'insert' && strlen(variable_get('nodegoto_insert_'. $node->type,'')) > 0){
   
//storing only the nid is not sufficient, node_load cannot retrieve node from cache for insert
   
$_SESSION['nodegoto_node'] = $node;
  }

}
?>

and replace the existing nodegoto_node_form_submit function with this code:

<?php
/**
* Additional submit handlers
*/
function nodegoto_node_form_submit($form_id, $form_values) {
 
//insert
 
if (empty($form_values['nid'])) {
   
//gm change Sept 13, 2008: retrieve node from session so that the token module works with [nid]
   
if(isset($_SESSION['nodegoto_node'])){
     
$node = $_SESSION['nodegoto_node'];
      unset(
$_SESSION['nodegoto_node']);
    }
   
$nodeto = module_exists('token') ? token_replace(variable_get('nodegoto_insert_'. $form_values['type'], ''), 'node', $node) : variable_get('nodegoto_insert_'. $form_values['type'], '');
  }
 
//update
 
else {
   
//gm change July 12, 2008: only with $node instantiated can the token module replace CCK fields
   
$node = node_load($form_values['nid'], NULL, FALSE);
   
$nodeto = module_exists('token') ? token_replace(variable_get('nodegoto_update_'. $form_values['type'], ''), 'node', $node) : variable_get('nodegoto_update_'. $form_values['type'], '');
  }
  if (
variable_get('nodegoto_camefrom', 0) == 1) {
    if(
$form_values['nid']) {
     
$nid = $form_values['nid'];
    }
    else {
     
$name = db_prefix_tables('{node}_nid');
     
$nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $name));
    }
   
$camefrom = 'nid='. $nid;
    return array(
$nodeto, $camefrom);
  }
  else {
    return
$nodeto;
  }
}
?>

I have tried only storing the node id in the session, but then the nodegoto_node_form_submit function needs to actually access the database to instantiate $node during an insert - did not look good to me.

#9

Hi Gerald!

good job. it works!!

thank you very much

Dam
http://www.squadrainformatica.com

#10

Status:active» needs review

Finally the patch for the issue posted above; same code as posted in comment #8. The patch fixes the issue that node-related tokens were not working for insert and update because the $node object was not instantiated. It does NOT fix this in the event of a node deletion.

AttachmentSize
NodeGoTo-260098-5.patch 1.93 KB

#11

Hi GeraldMengisen,

Thanks so Much!

Token [nid] was not working for me too. I could get it working only due to the provided patch.

Thanks for this great help.

#12

GeraldMengisen, thanks for the patch.

Here's a small note:

NodeGoTo-260098-5.patch in #10 contains 3 typos (noTegoto instead of noDegoto).