commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / ctools / ctools_plugin_example / plugins / content_types / relcontext_content_type.inc
1 <?php
2
3
4 /**
5 * @file
6 * Content type that displays the relcontext context type.
7 *
8 * This example is for use with the relcontext relationship to show
9 * how we can get a relationship-context into a data type.
10 */
11
12 /**
13 * Plugins are described by creating a $plugin array which will be used
14 * by the system that includes this file.
15 */
16 $plugin = array(
17 // Used in add content dialogs.
18 'title' => t('CTools example relcontext content type'),
19 'admin info' => 'ctools_plugin_example_relcontext_content_type_admin_info',
20 'content_types' => 'relcontext_content_type',
21 'single' => TRUE,
22 'render callback' => 'relcontext_content_type_render',
23 // Icon goes in the directory with the content type. Here, in plugins/content_types.
24 'icon' => 'icon_example.png',
25 'description' => t('Relcontext content type - works with relcontext context.'),
26 'required context' => new ctools_context_required(t('Relcontext'), 'relcontext'),
27 'category' => array(t('CTools Examples'), -9),
28 'edit form' => 'relcontext_edit_form',
29
30 // this example does not provide 'admin info', which would populate the
31 // panels builder page preview.
32
33 );
34
35 /**
36 * Run-time rendering of the body of the block.
37 *
38 * @param $subtype
39 * @param $conf
40 * Configuration as done at admin time
41 * @param $args
42 * @param $context
43 * Context - in this case we don't have any
44 *
45 * @return
46 * An object with at least title and content members
47 */
48 function relcontext_content_type_render($subtype, $conf, $args, $context) {
49 $data = $context->data;
50 $block = new stdClass();
51
52 // Don't forget to check this data if it's untrusted.
53 // The title actually used in rendering.
54 $block->title = "Relcontext content type";
55 $block->content = t("
56 This is a block of data created by the Relcontent content type.
57 Data in the block may be assembled from static text (like this) or from the
58 content type settings form (\$conf) for the content type, or from the context
59 that is passed in. <br />
60 In our case, the configuration form (\$conf) has just one field, 'config_item_1;
61 and it's configured with:
62 ");
63 if (!empty($conf)) {
64 $block->content .= '<div style="border: 1px solid red;">' . var_export($conf['config_item_1'], TRUE) . '</div>';
65 }
66 if (!empty($context)) {
67 $block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
68 var_export($args, TRUE) . '</div>';
69 }
70 $block->content .= '<br />And the relcontext context ($context->data->description)
71 (which was created from a
72 simplecontext context) was <div style="border: 1px solid green;" >' .
73 print_r($context->data->description, TRUE) . '</div>';
74 return $block;
75 }
76
77 /**
78 * 'Edit' callback for the content type.
79 * This example just returns a form.
80 *
81 */
82 function relcontext_edit_form($form, &$form_state) {
83 $conf = $form_state['conf'];
84
85 $form['config_item_1'] = array(
86 '#type' => 'textfield',
87 '#title' => t('Config Item 1 (relcontext)'),
88 '#size' => 50,
89 '#description' => t('Setting for relcontext.'),
90 '#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
91 '#prefix' => '<div class="clear-block no-float">',
92 '#suffix' => '</div>',
93 );
94 return $form;
95 }
96
97 function relcontext_edit_form_submit($form, &$form_state) {
98 foreach (element_children($form) as $key) {
99 if (!empty($form_state['values'][$key])) {
100 $form_state['conf'][$key] = $form_state['values'][$key];
101 }
102 }
103 }