Projet

Général

Profil

Paste
Télécharger (1,09 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / arguments / nid.inc @ c304a780

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide an argument handler for a node id.
6
 */
7

    
8
/**
9
 * Plugins are described by creating a $plugin array which will be used
10
 * by the system that includes this file.
11
 */
12
$plugin = array(
13
  'title' => t("Node: ID"),
14
  'keyword' => 'node',
15
  'description' => t('Creates a node context from a node ID argument.'),
16
  'context' => 'ctools_argument_nid_context',
17
  'placeholder form' => array(
18
    '#type' => 'textfield',
19
    '#description' => t('Enter the node ID of a node for this argument'),
20
  ),
21
  'no ui' => TRUE,
22
);
23

    
24
/**
25
 * Discover if this argument gives us the node we crave.
26
 */
27
function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
28
  // If unset it wants a generic, unfilled context.
29
  if ($empty) {
30
    return ctools_context_create_empty('node');
31
  }
32

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

    
38
  if (!is_numeric($arg)) {
39
    return FALSE;
40
  }
41

    
42
  $node = node_load($arg);
43
  if (!$node) {
44
    return FALSE;
45
  }
46

    
47
  return ctools_context_create('node', $node);
48
}