IT is not possible to pass variables to eval'd code, I know, but at least we could provide some featured APIs for this?

I now depend on helpers module, for example:

/**
 * Find out if the current page is a node page.
 * @return TRUE if the page is a node, FALSE if it is another page.
 */
function is_node_page() {
 if (arg(0) == 'node' && is_numeric(arg(1))) {
   return TRUE;
 }
 return FALSE;
}

/**
 * Grab the current 'active' node
 * An active node is the one node 123 as shown on page with path node/123, or
 * its aliased path(s).
 * @return $node object if the page is a node, empty $node object if it is not a
 * node, or if we cannot see it, for any valid reason.
 */
function node_load_current() {
 $node = new stdClass();

 if (is_node_page()) {
   $node = node_load(arg(1));
 }

 return $node;
}

But we need something that makes $node available on_validate and _preview.

Comments

fago’s picture

hm, yes this approach looks fine for node updates. But as you said for node creation things are more difficult. For sure the easiest way is to use the token module.

But for those going with php: To get the appropriate $node one needs to get the global $form_values, which is an array representation of the node. This should do it for both cases.

fago’s picture

Version: master » 5.x-1.x-dev

I've added the $form_values tip to the README. However any code that makes $node available as pattern would be still nice..

gaurav.kapoor’s picture

Issue summary: View changes
Status: Active » Closed (outdated)