Mercurial > hg > rr-repo
comparison sites/all/modules/ctools/plugins/arguments/rid.inc @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * | |
6 * Plugin to provide an argument handler for a node revision 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("Revision: ID"), | |
15 'keyword' => 'revision', | |
16 'description' => t('Creates a node context from a revision ID argument.'), | |
17 'context' => 'ctools_argument_rid_context', | |
18 'placeholder form' => array( | |
19 '#type' => 'textfield', | |
20 '#description' => t('Enter the revision ID of a node for this argument'), | |
21 ), | |
22 ); | |
23 | |
24 /** | |
25 * Discover if this argument gives us the node we crave. | |
26 */ | |
27 function ctools_argument_rid_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 $nid = db_query('SELECT nid FROM {node_revisions} WHERE vid = :vid', array(':vid' => $arg))->fetchField(); | |
43 $node = node_load($nid, $arg); | |
44 if (!$node) { | |
45 return FALSE; | |
46 } | |
47 | |
48 return ctools_context_create('node', $node); | |
49 } | |
50 |