1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* "No context" sample content type. It operates with no context at all. It would
|
6
|
* be basically the same as a 'custom content' block, but it's not even that
|
7
|
* sophisticated.
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Plugins are described by creating a $plugin array which will be used
|
12
|
* by the system that includes this file.
|
13
|
*/
|
14
|
$plugin = array(
|
15
|
'title' => t('CTools example no context content type'),
|
16
|
'description' => t('No context content type - requires and uses no context.'),
|
17
|
|
18
|
// 'single' => TRUE means has no subtypes.
|
19
|
'single' => TRUE,
|
20
|
// Constructor.
|
21
|
'content_types' => array('no_context_content_type'),
|
22
|
// Name of a function which will render the block.
|
23
|
'render callback' => 'no_context_content_type_render',
|
24
|
// The default context.
|
25
|
'defaults' => array(),
|
26
|
|
27
|
// This explicitly declares the config form. Without this line, the func would be
|
28
|
// ctools_plugin_example_no_context_content_type_edit_form.
|
29
|
'edit form' => 'no_context_content_type_edit_form',
|
30
|
|
31
|
// Icon goes in the directory with the content type.
|
32
|
'icon' => 'icon_example.png',
|
33
|
'category' => array(t('CTools Examples'), -9),
|
34
|
|
35
|
// This example does not provide 'admin info', which would populate the
|
36
|
// panels builder page preview.
|
37
|
);
|
38
|
|
39
|
/**
|
40
|
* Run-time rendering of the body of the block.
|
41
|
*
|
42
|
* @param $subtype
|
43
|
* @param $conf
|
44
|
* Configuration as done at admin time.
|
45
|
* @param $args
|
46
|
* @param $context
|
47
|
* Context - in this case we don't have any.
|
48
|
*
|
49
|
* @return
|
50
|
* An object with at least title and content members.
|
51
|
*/
|
52
|
function no_context_content_type_render($subtype, $conf, $args, $context) {
|
53
|
$block = new stdClass();
|
54
|
|
55
|
$ctools_help = theme('advanced_help_topic', array('module' => 'ctools', 'topic' => 'plugins', 'type' => 'title'));
|
56
|
$ctools_plugin_example_help = theme('advanced_help_topic', array('module' => 'ctools_plugin_example', 'topic' => 'Chaos-Tools--CTools--Plugin-Examples', 'type' => 'title'));
|
57
|
|
58
|
// The title actually used in rendering.
|
59
|
$block->title = check_plain("No-context content type");
|
60
|
$block->content = t("
|
61
|
<div>Welcome to the CTools Plugin Example demonstration content type.
|
62
|
|
63
|
This block is a content type which requires no context at all. It's like a custom block,
|
64
|
but not even that sophisticated.
|
65
|
|
66
|
For more information on the example plugins, please see the advanced help for
|
67
|
|
68
|
{$ctools_help} and {$ctools_plugin_example_help}
|
69
|
</div>
|
70
|
");
|
71
|
if (!empty($conf)) {
|
72
|
$block->content .= '<div>The only information that can be displayed in this block comes from the code and its settings form: </div>';
|
73
|
$block->content .= '<div style="border: 1px solid red;">' . var_export($conf, TRUE) . '</div>';
|
74
|
}
|
75
|
|
76
|
return $block;
|
77
|
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* 'Edit form' callback for the content type.
|
82
|
* This example just returns a form; validation and submission are standard drupal
|
83
|
* Note that if we had not provided an entry for this in hook_content_types,
|
84
|
* this could have had the default name
|
85
|
* ctools_plugin_example_no_context_content_type_edit_form.
|
86
|
*/
|
87
|
function no_context_content_type_edit_form($form, &$form_state) {
|
88
|
$conf = $form_state['conf'];
|
89
|
$form['item1'] = array(
|
90
|
'#type' => 'textfield',
|
91
|
'#title' => t('Item1'),
|
92
|
'#size' => 50,
|
93
|
'#description' => t('The setting for item 1.'),
|
94
|
'#default_value' => !empty($conf['item1']) ? $conf['item1'] : '',
|
95
|
'#prefix' => '<div class="clear-block no-float">',
|
96
|
'#suffix' => '</div>',
|
97
|
);
|
98
|
$form['item2'] = array(
|
99
|
'#type' => 'textfield',
|
100
|
'#title' => t('Item2'),
|
101
|
'#size' => 50,
|
102
|
'#description' => t('The setting for item 2'),
|
103
|
'#default_value' => !empty($conf['item2']) ? $conf['item2'] : '',
|
104
|
'#prefix' => '<div class="clear-block no-float">',
|
105
|
'#suffix' => '</div>',
|
106
|
);
|
107
|
return $form;
|
108
|
}
|
109
|
|
110
|
function no_context_content_type_edit_form_submit($form, &$form_state) {
|
111
|
foreach (array('item1', 'item2') as $key) {
|
112
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
113
|
}
|
114
|
}
|