home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (nid.inc)

This example Drupal source code file (nid.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

arg, args, array, context, ctools_argument_nid_context, description, false, function, id, if, node, null, php, return

The nid.inc Drupal example source code

// $Id: nid.inc,v 2010/01/29 20:18:25 merlinofchaos Exp $

 * @file
 * Plugin to provide an argument handler for a node id

 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
$plugin = array(
  'title' => t("Node: ID"),
  'keyword' => 'node',
  'description' => t('Creates a node context from a node ID argument.'),
  'context' => 'ctools_argument_nid_context',
  'placeholder form' => array(
    '#type' => 'textfield',
    '#description' => t('Enter the node ID of a node for this argument'),

 * Discover if this argument gives us the node we crave.
function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  // If unset it wants a generic, unfilled context.
  if ($empty) {
    return ctools_context_create_empty('node');

  // We can accept either a node object or a pure nid.
  if (is_object($arg)) {
    return ctools_context_create('node', $arg);

  if (!is_numeric($arg)) {
    return FALSE;

  $node = node_load($arg);
  if (!$node) {
    return FALSE;

  return ctools_context_create('node', $node);

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal nid.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.