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