1
|
<?php
|
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.
|
9
|
*
|
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
|
*/
|
17
|
function panels_mini_panels_mini_ctools_content_types() {
|
18
|
return array(
|
19
|
'title' => t('Mini panels'),
|
20
|
'content type' => 'panels_mini_panels_mini_content_type_content_type',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Return each available mini panel available as a subtype.
|
26
|
*/
|
27
|
function 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
|
*/
|
35
|
function panels_mini_panels_mini_content_type_content_types($plugin) {
|
36
|
$types = array();
|
37
|
foreach (panels_mini_load_all() as $mini) {
|
38
|
$type = _panels_mini_panels_mini_content_type_content_type($mini);
|
39
|
if ($type) {
|
40
|
$types[$mini->name] = $type;
|
41
|
}
|
42
|
}
|
43
|
return $types;
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Return an info array describing a single mini panel.
|
48
|
*/
|
49
|
function _panels_mini_panels_mini_content_type_content_type($mini) {
|
50
|
if (empty($mini)) {
|
51
|
// The mini panel is deleted or missing.
|
52
|
return;
|
53
|
}
|
54
|
|
55
|
if (!empty($mini->disabled)) {
|
56
|
return;
|
57
|
}
|
58
|
|
59
|
$title = filter_xss_admin($mini->admin_title);
|
60
|
$type = array(
|
61
|
'title' => $title,
|
62
|
// For now mini panels will just use the contrib block icon.
|
63
|
'icon' => 'icon_mini_panel.png',
|
64
|
'description' => $title,
|
65
|
'category' => !empty($mini->category) ? $mini->category : t('Mini panel'),
|
66
|
);
|
67
|
if (!empty($mini->requiredcontexts)) {
|
68
|
$type['required context'] = array();
|
69
|
foreach ($mini->requiredcontexts as $context) {
|
70
|
$info = ctools_get_context($context['name']);
|
71
|
// TODO: allow an optional setting
|
72
|
$type['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
|
73
|
}
|
74
|
}
|
75
|
return $type;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Render a mini panel called from a panels display.
|
80
|
*/
|
81
|
function panels_mini_panels_mini_content_type_render($subtype, $conf, $panel_args, &$contexts) {
|
82
|
static $viewing = array();
|
83
|
$mini = panels_mini_load($subtype);
|
84
|
if (!$mini) {
|
85
|
return FALSE;
|
86
|
}
|
87
|
if (!empty($viewing[$mini->name])) {
|
88
|
return FALSE;
|
89
|
}
|
90
|
|
91
|
// Load up any contexts we might be using.
|
92
|
$context = ctools_context_match_required_contexts($mini->requiredcontexts, $contexts);
|
93
|
$mini->context = $mini->display->context = ctools_context_load_contexts($mini, FALSE, $context);
|
94
|
|
95
|
if (empty($mini) || !empty($mini->disabled)) {
|
96
|
return;
|
97
|
}
|
98
|
$viewing[$mini->name] = TRUE;
|
99
|
|
100
|
$mini->display->args = $panel_args;
|
101
|
$mini->display->css_id = panels_mini_get_id($subtype);
|
102
|
$mini->display->owner = $mini;
|
103
|
// unique ID of this mini.
|
104
|
$mini->display->owner->id = $mini->name;
|
105
|
|
106
|
$block = new stdClass();
|
107
|
$block->module = 'panels_mini';
|
108
|
$block->delta = $subtype;
|
109
|
$block->content = panels_render_display($mini->display);
|
110
|
$block->title = $mini->display->get_title();
|
111
|
|
112
|
if (user_access('administer mini panels')) {
|
113
|
$block->admin_links = array(
|
114
|
array(
|
115
|
'title' => t('Configure mini panel'),
|
116
|
'href' => "admin/structure/mini-panels/list/$subtype/edit/content",
|
117
|
'query' => drupal_get_destination(),
|
118
|
),
|
119
|
);
|
120
|
}
|
121
|
|
122
|
unset($viewing[$mini->name]);
|
123
|
return $block;
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Edit form for the mini panel content type.
|
128
|
*/
|
129
|
function panels_mini_panels_mini_content_type_edit_form($form, &$form_state) {
|
130
|
// Empty form to ensure we have the override title + context gadgets.
|
131
|
return $form;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Provide the administrative title of a mini panel.
|
136
|
*/
|
137
|
function panels_mini_panels_mini_content_type_admin_title($subtype, $conf) {
|
138
|
$mini = panels_mini_load($subtype);
|
139
|
if (!$mini) {
|
140
|
return t('Deleted/missing mini panel @name', array('@name' => $subtype));
|
141
|
}
|
142
|
|
143
|
$title = filter_xss_admin($mini->admin_title);
|
144
|
if (empty($title)) {
|
145
|
$title = t('Untitled mini panel');
|
146
|
}
|
147
|
return $title;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Callback to provide administrative info. Provide links to edit the mini
|
152
|
* panel.
|
153
|
*/
|
154
|
function panels_mini_panels_mini_content_type_admin_info($subtype, $conf) {
|
155
|
$mini = panels_mini_load($subtype);
|
156
|
if (!$mini) {
|
157
|
return FALSE;
|
158
|
}
|
159
|
|
160
|
$block = new stdClass();
|
161
|
$block->title = $mini->admin_title;
|
162
|
$admin_pages = array(
|
163
|
t('Settings') => 'basic',
|
164
|
t('Context') => 'context',
|
165
|
t('Layout') => 'layout',
|
166
|
t('Content') => 'content',
|
167
|
);
|
168
|
|
169
|
$links = array();
|
170
|
foreach ($admin_pages as $title => $tail) {
|
171
|
$links[] = l($title, 'admin/structure/mini-panels/list/' . $subtype . '/edit/' . $tail, array('query' => drupal_get_destination()));
|
172
|
}
|
173
|
|
174
|
$block->content = theme('item_list', array('items' => $links));
|
175
|
return $block;
|
176
|
}
|