1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
*
|
6 |
|
|
* Plugin to provide an argument handler for a node id
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
11 |
|
|
* by the system that includes this file.
|
12 |
|
|
*/
|
13 |
|
|
$plugin = array(
|
14 |
|
|
'title' => t("Node: ID"),
|
15 |
|
|
'keyword' => 'node',
|
16 |
|
|
'description' => t('Creates a node context from a node ID argument.'),
|
17 |
|
|
'context' => 'ctools_argument_nid_context',
|
18 |
|
|
'placeholder form' => array(
|
19 |
|
|
'#type' => 'textfield',
|
20 |
|
|
'#description' => t('Enter the node ID of a node for this argument'),
|
21 |
|
|
),
|
22 |
|
|
'no ui' => TRUE,
|
23 |
|
|
);
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Discover if this argument gives us the node we crave.
|
27 |
|
|
*/
|
28 |
|
|
function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
29 |
|
|
// If unset it wants a generic, unfilled context.
|
30 |
|
|
if ($empty) {
|
31 |
|
|
return ctools_context_create_empty('node');
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
// We can accept either a node object or a pure nid.
|
35 |
|
|
if (is_object($arg)) {
|
36 |
|
|
return ctools_context_create('node', $arg);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
if (!is_numeric($arg)) {
|
40 |
|
|
return FALSE;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
$node = node_load($arg);
|
44 |
|
|
if (!$node) {
|
45 |
|
|
return FALSE;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
return ctools_context_create('node', $node);
|
49 |
|
|
}
|