#114772 (by Tobias Maier) allow custom content to specify CSS Info
[project/panels.git] / content_types / custom.inc
CommitLineData
9f3609c9
EM
1<?php\r
2/**\r
3 * Callback function to supply a list of content types.\r
4 */\r
5function panels_custom_panels_content_types() {\r
6 $items['custom'] = array(\r
7 'callback' => 'panels_content_custom',\r
8 'admin' => 'panels_admin_custom',\r
9 );\r
10 return $items;\r
11}\r
12\r
13/**\r
14 * Output function for the 'custom' content type. Outputs a custom\r
15 * based on the module and delta supplied in the configuration.\r
16 */\r
17function panels_content_custom($conf) {\r
0701fd15
EM
18 $title = filter_xss_admin($conf['title']);
19 $css_id = filter_xss_admin($conf['css_id']);
20 $css_class = filter_xss_admin($conf['css_class']);\r
21 $body = check_markup($conf['body'], $conf['format'], FALSE);\r
22 return theme('panels_content_custom', $title, $body, $css_id, $css_class);\r
9f3609c9
EM
23}\r
24\r
0701fd15
EM
25function theme_panels_content_custom($title, $body, $css_id = NULL, $css_class = NULL) {
26 if ($css_id) {
27 $css_id = ' id="'. $css_id .'"';
28 }
29 if ($css_class) {
30 $css_class = ' '. $css_class;
31 }\r
32 $output = '<div class="panel-custom'. $css_class .'"'. $css_id .'>';\r
9f3609c9
EM
33 if ($title) {\r
34 $output .= '<h2 class="title">' . $title . '</h2>';\r
35 }\r
36 $output .= $body;\r
37 $output .= '</div>';\r
9f3609c9
EM
38 return $output;\r
39}\r
40/** \r
41 * Callback to perform administrative functions on the content block\r
42 */\r
43function panels_admin_custom($op, &$arg, $arg2 = NULL) {\r
44 switch ($op) {\r
45 case 'list':\r
46 $conf = $arg;\r
47 return '<strong>Custom</strong>: ' . filter_xss_admin($conf['title']);\r
48 case 'add button':\r
49 $form['title'] = array(\r
50 '#title' => t('Enter an optional title for custom content you define'),\r
51 '#type' => 'textfield',\r
52 '#maxlength' => 512,\r
53 '#weight' => -10,\r
54 );\r
55 $form['submit'] = array(\r
56 '#type' => 'button',\r
57 '#value' => t('Add custom'),\r
58 );\r
59\r
60 $form['#prefix'] = '<div class="container-inline">';\r
61 $form['#suffix'] = '</div>';\r
62 return $form;\r
63 case 'add':\r
64 if ($_POST['op'] != t('Add custom')) {\r
65 return;\r
66 }\r
67 return $arg;\r
68 case 'edit':\r
69 $conf = &$arg;\r
70 $form['title'] = array(\r
71 '#type' => 'textfield',\r
72 '#default_value' => $conf['title'],\r
73 '#title' => t('Title'),\r
74 '#description' => t('Title'),\r
75 '#size' => 15,\r
76 );\r
77 $form['body'] = array(\r
78 '#title' => t('Body'),\r
79 '#type' => 'textarea',\r
80 '#default_value' => $conf['body'],\r
81 '#rows' => 10,\r
82 '#cols' => 20,\r
83 );\r
84 $arg2[] = 'format';\r
85 $form['format'] = filter_form($conf['format'], 1, $arg2);\r
0701fd15
EM
86
87 $form['css_id'] = array(\r
88 '#type' => 'textfield',\r
89 '#default_value' => $conf['css_id'],\r
90 '#title' => t('CSS ID'),\r
91 '#description' => t('CSS ID of this custom content.'),
92 '#weight' => 2,\r
93 '#size' => 15,\r
94 );
95 $form['css_class'] = array(\r
96 '#type' => 'textfield',\r
97 '#default_value' => $conf['css_class'],\r
98 '#title' => t('CSS class'),\r
99 '#description' => t('CSS class of this custom content.'),
100 '#weight' => 2,\r
101 '#size' => 15,\r
102 );\r
9f3609c9
EM
103 return $form;\r
104 case 'validate':\r
105 // This one has nothing to validate.\r
106 $form = &$arg;\r
107 return;\r
108 case 'save':\r
109 // For this one, the form values go directly into the config.\r
110 $form = &$arg;\r
111 return $form;\r
112 }\r
113}\r