1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Sample ctools context type plugin that
|
6 |
|
|
* is used in this demo to create a relcontext from an existing simplecontext.
|
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("Relcontext"),
|
15 |
|
|
'description' => t('A relcontext object.'),
|
16 |
|
|
// Function to create the relcontext.
|
17 |
|
|
'context' => 'ctools_plugin_example_context_create_relcontext',
|
18 |
|
|
// Function that does the settings.
|
19 |
|
|
'settings form' => 'relcontext_settings_form',
|
20 |
|
|
'keyword' => 'relcontext',
|
21 |
|
|
'context name' => 'relcontext',
|
22 |
|
|
);
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Create a context, either from manual configuration (form) or from an argument on the URL.
|
26 |
|
|
*
|
27 |
|
|
* @param $empty
|
28 |
|
|
* If true, just return an empty context.
|
29 |
|
|
* @param $data
|
30 |
|
|
* If from settings form, an array as from a form. If from argument, a string.
|
31 |
|
|
* @param $conf
|
32 |
|
|
* TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
|
33 |
|
|
*
|
34 |
|
|
* @return
|
35 |
|
|
* a Context object.
|
36 |
|
|
*/
|
37 |
|
|
function ctools_plugin_example_context_create_relcontext($empty, $data = NULL, $conf = FALSE) {
|
38 |
|
|
$context = new ctools_context('relcontext');
|
39 |
|
|
$context->plugin = 'relcontext';
|
40 |
|
|
if ($empty) {
|
41 |
|
|
return $context;
|
42 |
|
|
}
|
43 |
|
|
if ($conf) {
|
44 |
|
|
if (!empty($data)) {
|
45 |
|
|
$context->data = new stdClass();
|
46 |
|
|
// For this simple item we'll just create our data by stripping non-alpha and
|
47 |
|
|
// adding 'sample_relcontext_setting' to it.
|
48 |
|
|
$context->data->description = 'relcontext_from__' . preg_replace('/[^a-z]/i', '', $data['sample_relcontext_setting']);
|
49 |
|
|
$context->data->description .= '_from_configuration_sample_simplecontext_setting';
|
50 |
|
|
$context->title = t("Relcontext context from simplecontext");
|
51 |
|
|
return $context;
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
else {
|
55 |
|
|
// $data is coming from an arg - it's just a string.
|
56 |
|
|
// This is used for keyword.
|
57 |
|
|
$context->title = "relcontext_" . $data->data->description;
|
58 |
|
|
$context->argument = $data->argument;
|
59 |
|
|
// Make up a bogus context.
|
60 |
|
|
$context->data = new stdClass();
|
61 |
|
|
// For this simple item we'll just create our data by stripping non-alpha and
|
62 |
|
|
// prepend 'relcontext_' and adding '_created_from_from_simplecontext' to it.
|
63 |
|
|
$context->data->description = 'relcontext_' . preg_replace('/[^a-z]/i', '', $data->data->description);
|
64 |
|
|
$context->data->description .= '_created_from_simplecontext';
|
65 |
|
|
return $context;
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
function relcontext_settings_form($conf, $external = FALSE) {
|
70 |
|
|
$form = array();
|
71 |
|
|
|
72 |
|
|
$form['sample_relcontext_setting'] = array(
|
73 |
|
|
'#type' => 'textfield',
|
74 |
|
|
'#title' => t('Relcontext setting'),
|
75 |
|
|
'#size' => 50,
|
76 |
|
|
'#description' => t('Just an example setting.'),
|
77 |
|
|
'#default_value' => !empty($conf['sample_relcontext_setting']) ? $conf['sample_relcontext_setting'] : '',
|
78 |
|
|
'#prefix' => '<div class="clear-block no-float">',
|
79 |
|
|
'#suffix' => '</div>',
|
80 |
|
|
);
|
81 |
|
|
return $form;
|
82 |
|
|
}
|