Stripping CVS keywords
[project/panels.git] / panels_mini / plugins / content_types / panels_mini.inc
CommitLineData
942819fd 1<?php
942819fd
EM
2
3/**
4 * @file
5 * Contains the content type plugin for a mini panel. While this does not
6 * need to be broken out into a .inc file, it's convenient that we do so
7 * that we don't load code unneccessarily. Plus it demonstrates plugins
8 * in modules other than Panels itself.
e0d0f04f 9 *
942819fd
EM
10 */
11
12/**
13 * Specially named hook. for .inc file. This looks a little silly due to the
14 * redundancy, but that's really just because the content type shares a
15 * name with the module.
16 */
746ca3a2
EM
17function panels_mini_panels_mini_ctools_content_types() {
18 return array(
942819fd 19 'title' => t('Mini panels'),
6d72ae18 20 'content type' => 'panels_mini_panels_mini_content_type_content_type',
942819fd 21 );
942819fd
EM
22}
23
24/**
25 * Return each available mini panel available as a subtype.
26 */
6d72ae18
SB
27function panels_mini_panels_mini_content_type_content_type($subtype_id, $plugin) {
28 $mini = panels_mini_load($subtype_id);
29 return _panels_mini_panels_mini_content_type_content_type($mini);
30}
31
32/**
33 * Return each available mini panel available as a subtype.
34 */
746ca3a2 35function panels_mini_panels_mini_content_type_content_types($plugin) {
942819fd 36 $types = array();
942819fd 37 foreach (panels_mini_load_all() as $mini) {
6d72ae18
SB
38 $type = _panels_mini_panels_mini_content_type_content_type($mini);
39 if ($type) {
40 $types[$mini->name] = $type;
942819fd
EM
41 }
42 }
43 return $types;
44}
45
6d72ae18
SB
46/**
47 * Return an info array describing a single mini panel.
48 */
49function _panels_mini_panels_mini_content_type_content_type($mini) {
50 if (!empty($mini->disabled)) {
51 return;
52 }
53
50fb37ca 54 $title = filter_xss_admin($mini->admin_title);
6d72ae18
SB
55 $type = array(
56 'title' => $title,
57 // For now mini panels will just use the contrib block icon.
58 'icon' => 'icon_mini_panel.png',
59 'description' => $title,
60 'category' => !empty($mini->category) ? $mini->category : t('Mini panel'),
61 );
62 if (!empty($mini->requiredcontexts)) {
63 $type['required context'] = array();
64 foreach ($mini->requiredcontexts as $context) {
65 $info = ctools_get_context($context['name']);
66 // TODO: allow an optional setting
67 $type['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
68 }
69 }
70 return $type;
71}
942819fd
EM
72
73/**
74 * Render a mini panel called from a panels display.
75 */
746ca3a2 76function panels_mini_panels_mini_content_type_render($subtype, $conf, $panel_args, &$contexts) {
648a4168 77 static $viewing = array();
746ca3a2 78 $mini = panels_mini_load($subtype);
942819fd
EM
79 if (!$mini) {
80 return FALSE;
81 }
648a4168
EM
82 if (!empty($viewing[$mini->name])) {
83 return FALSE;
84 }
942819fd
EM
85
86 // Load up any contexts we might be using.
87 $context = ctools_context_match_required_contexts($mini->requiredcontexts, $contexts);
88 $mini->context = $mini->display->context = ctools_context_load_contexts($mini, FALSE, $context);
89
90 if (empty($mini) || !empty($mini->disabled)) {
91 return;
92 }
648a4168 93 $viewing[$mini->name] = TRUE;
942819fd
EM
94
95 $mini->display->args = $panel_args;
746ca3a2 96 $mini->display->css_id = panels_mini_get_id($subtype);
942819fd
EM
97 $mini->display->owner = $mini;
98 // unique ID of this mini.
99 $mini->display->owner->id = $mini->name;
100
101 $block = new stdClass();
102 $block->module = 'panels_mini';
746ca3a2 103 $block->delta = $subtype;
942819fd 104 $block->content = panels_render_display($mini->display);
50fb37ca 105 $block->title = $mini->display->get_title();
648a4168
EM
106
107 unset($viewing[$mini->name]);
942819fd
EM
108 return $block;
109}
110
111/**
746ca3a2 112 * Edit form for the mini panel content type.
942819fd 113 */
746ca3a2
EM
114function panels_mini_panels_mini_content_type_edit_form(&$form, &$form_state) {
115 // Empty form to ensure we have the override title + context gadgets.
942819fd
EM
116}
117
118/**
119 * Provide the administrative title of a mini panel.
120 */
746ca3a2
EM
121function panels_mini_panels_mini_content_type_admin_title($subtype, $conf) {
122 $mini = panels_mini_load($subtype);
942819fd 123 if (!$mini) {
746ca3a2 124 return t('Deleted/missing mini panel @name', array('@name' => $subtype));
942819fd
EM
125 }
126
50fb37ca 127 $title = filter_xss_admin($mini->admin_title);
942819fd
EM
128 if (empty($title)) {
129 $title = t('Untitled mini panel');
130 }
131 return $title;
132}
133