1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Sample plugin to provide an argument handler for a simplecontext.
|
6
|
*
|
7
|
* Given any argument to the page, simplecontext will get it
|
8
|
* and turn it into a piece of data (a "context") just by adding some text to it.
|
9
|
* Normally, the argument would be a key into some database (like the node
|
10
|
* database, for example, and the result of using the argument would be to load
|
11
|
* a specific "context" or data item that we can use elsewhere.
|
12
|
*/
|
13
|
|
14
|
/**
|
15
|
* Plugins are described by creating a $plugin array which will be used
|
16
|
* by the system that includes this file.
|
17
|
*/
|
18
|
$plugin = array(
|
19
|
'title' => t("Simplecontext arg"),
|
20
|
// Keyword to use for %substitution.
|
21
|
'keyword' => 'simplecontext',
|
22
|
'description' => t('Creates a "simplecontext" from the arg.'),
|
23
|
'context' => 'simplecontext_arg_context',
|
24
|
// placeholder_form is used in panels preview, for example, so we can
|
25
|
// preview without getting the arg from a URL.
|
26
|
'placeholder form' => array(
|
27
|
'#type' => 'textfield',
|
28
|
'#description' => t('Enter the simplecontext arg'),
|
29
|
),
|
30
|
);
|
31
|
|
32
|
/**
|
33
|
* Get the simplecontext context using the arg. In this case we're just going
|
34
|
* to manufacture the context from the data in the arg, but normally it would
|
35
|
* be an API call, db lookup, etc.
|
36
|
*/
|
37
|
function simplecontext_arg_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
38
|
// If $empty == TRUE it wants a generic, unfilled context.
|
39
|
if ($empty) {
|
40
|
return ctools_context_create_empty('simplecontext');
|
41
|
}
|
42
|
// Do whatever error checking is required, returning FALSE if it fails the test
|
43
|
// Normally you'd check
|
44
|
// for a missing object, one you couldn't create, etc.
|
45
|
if (empty($arg)) {
|
46
|
return FALSE;
|
47
|
}
|
48
|
return ctools_context_create('simplecontext', $arg);
|
49
|
}
|