Get current node ID

chrism2671 - May 18, 2008 - 10:05
Project:Custom filter
Version:5.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

$node->nid doesn't appear to be available in the php-code section of the filter. What do you suppose is the best way of getting the nid for the current node? (Might want to reassign this as a feature request)

Awesome module by the way, a real gem.

#1

arhip - May 27, 2008 - 15:48

Hi,

Filters are processed before node object loaded, that's why we couldn't merely use $node object. See issue #229936: Date issue in php-enabled custom filter for details. There a patch in comment #2, or you can copy and paste this code to your customfilter.module

<?php
function customfilter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global
$_customfilter_code_vars;

  if (
$op == 'load') {
   
$_customfilter_code_vars->node = $node;
  }
}
?>

In the filter's code, use $vars->node->nid to get the node's nid, or $vars->node to get node object. This patch forces drupal to load node before the filter get processed.

Hope it helps.

Thanks for your kind words.

#2

kiamlaluno - July 1, 2009 - 13:32
Status:active» fixed

I am setting this support request as fixed because it got an answer. The reported code is the one used in the 6.x-2 branch.

#3

System Message - July 15, 2009 - 13:40
Status:fixed» closed

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

#4

kiamlaluno - July 15, 2009 - 15:49
Title:Get current node id» Get current node ID
 
 

Drupal is a registered trademark of Dries Buytaert.