GlobalNode

dllh - April 16, 2007 - 18:16

Adds a nodeapi hook that adds the variable $GLOBALS['globalnode'] containing attributes for a given node. Which attributes are displayed is determined in the GlobalNode settings.

Sometimes it's useful to have information about a node in a scope that doesn't have access to the node by default. For example, in the block administration, you can write logic to determine when to display a given block. If you want a node to show up on all blog content, you need a rule that will catch instances where the uri is "/blog/", "/blog/some-title", and "/node/1234". The only way to catch "/node/1234" is to know the node type; else you might display the sidebar for other node types. As far as I've been able to tell, this information isn't easily gotten from the scope of the block display code.

Enter GlobalNode, which adds a nodeapi hook that adds the variable $GLOBALS['globalnode'] containing attributes for a given node. Which attributes are displayed is determined in the GlobalNode settings. In the example given above, I specify "type". This is then stored as $GLOBALS['globalnode']->type, which I can use in the block administration logic to show a sidebar for all nodes of type "blog".

There used to be in Drupal a global variable named $global_cache that could be used similarly, and this module does essentially what that variable did.

Example Usage:

<?php
 
if(($GLOBALS['globalnode']->list == false && $GLOBALS['globalnode']->type == 'blog') || preg_match('/^\/blog\/?/', $_SERVER['REQUEST_URI'])){
    return
TRUE;
  } 

?>

The block above demonstrates a potential usage. The "list" attribute is set to false by default and true when hook_nodeapi runs more than once (e.g. when there's more than one node, as in list views). This lets you dictate different behaviors for list views than for page views.

Releases

Official releasesDateSizeLinksStatus
5.x-1.12007-Jun-286.97 KBRecommended for 5.xThis is currently the recommended release for 5.x.
Development snapshotsDateSizeLinksStatus
5.x-1.x-dev2007-Jun-296.98 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.