1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugin to provide an argument handler for a node revision 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("Revision: ID"),
|
14
|
'keyword' => 'revision',
|
15
|
'description' => t('Creates a node context from a revision ID argument.'),
|
16
|
'context' => 'ctools_argument_rid_context',
|
17
|
'placeholder form' => array(
|
18
|
'#type' => 'textfield',
|
19
|
'#description' => t('Enter the revision ID of a node for this argument'),
|
20
|
),
|
21
|
);
|
22
|
|
23
|
/**
|
24
|
* Discover if this argument gives us the node we crave.
|
25
|
*/
|
26
|
function ctools_argument_rid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
27
|
// If unset it wants a generic, unfilled context.
|
28
|
if ($empty) {
|
29
|
return ctools_context_create_empty('node');
|
30
|
}
|
31
|
|
32
|
// We can accept either a node object or a pure nid.
|
33
|
if (is_object($arg)) {
|
34
|
return ctools_context_create('node', $arg);
|
35
|
}
|
36
|
|
37
|
if (!is_numeric($arg)) {
|
38
|
return FALSE;
|
39
|
}
|
40
|
|
41
|
$nid = db_query('SELECT nid FROM {node_revision} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
|
42
|
$node = node_load($nid, $arg);
|
43
|
if (!$node) {
|
44
|
return FALSE;
|
45
|
}
|
46
|
|
47
|
return ctools_context_create('node', $node);
|
48
|
}
|