1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* @file
|
6 |
|
|
* Sample ctools content type that takes advantage of context.
|
7 |
|
|
*
|
8 |
|
|
* This example uses the context it gets (simplecontext) to demo how a
|
9 |
|
|
* ctools content type can access and use context. Note that the simplecontext
|
10 |
|
|
* can be either configured manually into a panel or it can be retrieved via
|
11 |
|
|
* an argument.
|
12 |
|
|
*
|
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 content type'),
|
21 |
|
|
'content_types' => 'simplecontext_content_type',
|
22 |
|
|
// 'single' means not to be subtyped.
|
23 |
|
|
'single' => TRUE,
|
24 |
|
|
// Name of a function which will render the block.
|
25 |
|
|
'render callback' => 'simplecontext_content_type_render',
|
26 |
|
|
|
27 |
|
|
// Icon goes in the directory with the content type.
|
28 |
|
|
'icon' => 'icon_example.png',
|
29 |
|
|
'description' => t('Simplecontext content type - works with a simplecontext context.'),
|
30 |
|
|
'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
|
31 |
|
|
'edit form' => 'simplecontext_content_type_edit_form',
|
32 |
|
|
'admin title' => 'ctools_plugin_example_simplecontext_content_type_admin_title',
|
33 |
|
|
|
34 |
|
|
// presents a block which is used in the preview of the data.
|
35 |
|
|
// Pn Panels this is the preview pane shown on the panels building page.
|
36 |
|
|
'admin info' => 'ctools_plugin_example_simplecontext_content_type_admin_info',
|
37 |
|
|
'category' => array(t('CTools Examples'), -9),
|
38 |
|
|
);
|
39 |
|
|
|
40 |
|
|
function ctools_plugin_example_simplecontext_content_type_admin_title($subtype, $conf, $context = NULL) {
|
41 |
|
|
$output = t('Simplecontext');
|
42 |
|
|
if ($conf['override_title'] && !empty($conf['override_title_text'])) {
|
43 |
|
|
$output = filter_xss_admin($conf['override_title_text']);
|
44 |
|
|
}
|
45 |
|
|
return $output;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
|
|
* Callback to provide administrative info (the preview in panels when building
|
50 |
|
|
* a panel).
|
51 |
|
|
*
|
52 |
|
|
* In this case we'll render the content with a dummy argument and
|
53 |
|
|
* a dummy context.
|
54 |
|
|
*/
|
55 |
|
|
function ctools_plugin_example_simplecontext_content_type_admin_info($subtype, $conf, $context = NULL) {
|
56 |
|
|
$context = new stdClass();
|
57 |
|
|
$context->data = new stdClass();
|
58 |
|
|
$context->data->description = t("no real context");
|
59 |
|
|
$block = simplecontext_content_type_render($subtype, $conf, array("Example"), $context);
|
60 |
|
|
return $block;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* Run-time rendering of the body of the block (content type)
|
65 |
|
|
*
|
66 |
|
|
* @param $subtype
|
67 |
|
|
* @param $conf
|
68 |
|
|
* Configuration as done at admin time
|
69 |
|
|
* @param $args
|
70 |
|
|
* @param $context
|
71 |
|
|
* Context - in this case we don't have any
|
72 |
|
|
*
|
73 |
|
|
* @return
|
74 |
|
|
* An object with at least title and content members
|
75 |
|
|
*/
|
76 |
|
|
function simplecontext_content_type_render($subtype, $conf, $args, $context) {
|
77 |
|
|
$data = $context->data;
|
78 |
|
|
$block = new stdClass();
|
79 |
|
|
|
80 |
|
|
// Don't forget to check this data if it's untrusted.
|
81 |
|
|
// The title actually used in rendering.
|
82 |
|
|
$block->title = "Simplecontext content type";
|
83 |
|
|
$block->content = t("
|
84 |
|
|
This is a block of data created by the Simplecontext content type.
|
85 |
|
|
Data in the block may be assembled from static text (like this) or from the
|
86 |
|
|
content type settings form (\$conf) for the content type, or from the context
|
87 |
|
|
that is passed in. <br />
|
88 |
|
|
In our case, the configuration form (\$conf) has just one field, 'config_item_1;
|
89 |
|
|
and it's configured with:
|
90 |
|
|
");
|
91 |
|
|
if (!empty($conf)) {
|
92 |
|
|
$block->content .= '<div style="border: 1px solid red;">' . print_r(filter_xss_admin($conf['config_item_1']), TRUE) . '</div>';
|
93 |
|
|
}
|
94 |
|
|
if (!empty($context)) {
|
95 |
|
|
$block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
|
96 |
|
|
var_export($args, TRUE) . '</div>';
|
97 |
|
|
}
|
98 |
|
|
$block->content .= '<br />And the simplecontext context ($context->data->description) was <div style="border: 1px solid green;" >' .
|
99 |
|
|
print_r($context->data->description, TRUE) . '</div>';
|
100 |
|
|
return $block;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* 'Edit' callback for the content type.
|
105 |
|
|
* This example just returns a form.
|
106 |
|
|
*
|
107 |
|
|
*/
|
108 |
|
|
function simplecontext_content_type_edit_form($form, &$form_state) {
|
109 |
|
|
$conf = $form_state['conf'];
|
110 |
|
|
$form['config_item_1'] = array(
|
111 |
|
|
'#type' => 'textfield',
|
112 |
|
|
'#title' => t('Config Item 1 for simplecontext content type'),
|
113 |
|
|
'#size' => 50,
|
114 |
|
|
'#description' => t('The stuff for item 1.'),
|
115 |
|
|
'#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
|
116 |
|
|
'#prefix' => '<div class="clear-block no-float">',
|
117 |
|
|
'#suffix' => '</div>',
|
118 |
|
|
);
|
119 |
|
|
|
120 |
|
|
return $form;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
function simplecontext_content_type_edit_form_submit($form, &$form_state) {
|
124 |
|
|
foreach (element_children($form) as $key) {
|
125 |
|
|
if (!empty($form_state['values'][$key])) {
|
126 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
} |