1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
*
|
5
|
* This is the task handler plugin to handle an entity view.
|
6
|
* NOTE: This is named panelizer_node for historical reasons. It is too much
|
7
|
* of a pain to change the name of a task handler. This panelizes any entity
|
8
|
* not just a node.
|
9
|
*/
|
10
|
|
11
|
// Plugin definition
|
12
|
$plugin = array(
|
13
|
// is a 'context' handler type, meaning it supports the API of the
|
14
|
// context handlers provided by ctools context plugins.
|
15
|
'handler type' => 'context',
|
16
|
// Administrative fields.
|
17
|
'title' => t('Panelizer'),
|
18
|
'forms' => array(),
|
19
|
'admin title' => 'panelizer_panelizer_task_title',
|
20
|
'admin summary' => 'panelizer_panelizer_task_admin_summary',
|
21
|
'operations' => array(),
|
22
|
// Callback to render the data.
|
23
|
'render' => 'panelizer_panelizer_task_render',
|
24
|
// Callback to return addressable data
|
25
|
'addressable callback' => 'panelizer_panelizer_task_get_addressable',
|
26
|
|
27
|
'test' => 'panelizer_panelizer_task_test',
|
28
|
'visible' => TRUE,
|
29
|
|
30
|
// Provide custom panelizer specific contextual links.
|
31
|
'contextual link' => 'panelizer_panelizer_task_contextual_link',
|
32
|
|
33
|
'operations' => array(
|
34
|
'settings' => array(
|
35
|
'title' => t('General'),
|
36
|
'description' => t('Change general settings for this variant.'),
|
37
|
'form' => 'panelizer_panelizer_task_edit_settings',
|
38
|
),
|
39
|
'criteria' => array(
|
40
|
'title' => t('Selection rules'),
|
41
|
'description' => t('Control the criteria used to decide whether or not this variant is used.'),
|
42
|
'ajax' => FALSE,
|
43
|
'form' => array(
|
44
|
'order' => array(
|
45
|
'form' => t('Selection rules'),
|
46
|
),
|
47
|
'forms' => array(
|
48
|
'form' => array(
|
49
|
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
50
|
'form id' => 'ctools_context_handler_edit_criteria',
|
51
|
),
|
52
|
),
|
53
|
),
|
54
|
),
|
55
|
'context' => array(
|
56
|
'title' => t('Contexts'),
|
57
|
'ajax' => FALSE,
|
58
|
'description' => t('Add additional context objects to this variant that can be used by the content.'),
|
59
|
'form' => array(
|
60
|
'order' => array(
|
61
|
'form' => t('Context'),
|
62
|
),
|
63
|
'forms' => array(
|
64
|
'form' => array(
|
65
|
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
66
|
'form id' => 'ctools_context_handler_edit_context',
|
67
|
),
|
68
|
),
|
69
|
),
|
70
|
),
|
71
|
),
|
72
|
'default conf' => array(
|
73
|
'title' => t('Panelizer'),
|
74
|
'contexts' => array(),
|
75
|
'relationships' => array(),
|
76
|
'context' => array(),
|
77
|
),
|
78
|
|
79
|
);
|
80
|
|
81
|
/**
|
82
|
* Figure out the correct context to use for this panelizer.
|
83
|
*/
|
84
|
function _panelizer_panelizer_task_get_context($handler, $contexts) {
|
85
|
if (isset($handler->conf['context']) && !empty($contexts[$handler->conf['context']])) {
|
86
|
return $contexts[$handler->conf['context']];
|
87
|
}
|
88
|
|
89
|
// If one was not set up, we could be using old, saved data. Assume that
|
90
|
// this means we just want the first context available.
|
91
|
if (!empty($contexts)) {
|
92
|
return reset($contexts);
|
93
|
}
|
94
|
|
95
|
// Fail!
|
96
|
return stdClass();
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Provide appropriate contextual links for Panelizer controled entities.
|
101
|
*/
|
102
|
function panelizer_panelizer_task_contextual_link($handler, $plugin, $contexts, $args) {
|
103
|
$links = array();
|
104
|
|
105
|
$context = _panelizer_panelizer_task_get_context($handler, $contexts);
|
106
|
if (empty($context->data)) {
|
107
|
return;
|
108
|
}
|
109
|
|
110
|
$entity = &$context->data;
|
111
|
|
112
|
if (empty($entity->panelizer['page_manager'])) {
|
113
|
return FALSE;
|
114
|
}
|
115
|
|
116
|
$panelizer = $entity->panelizer['page_manager'];
|
117
|
// One of these two will always be set.
|
118
|
$entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type;
|
119
|
|
120
|
if ($entity_handler = panelizer_entity_plugin_get_handler($entity_type)) {
|
121
|
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
|
122
|
|
123
|
// @todo there's code on the entity handler to do this path thing for us.
|
124
|
$bits = explode('/', $entity_handler->plugin['entity path']);
|
125
|
foreach ($bits as $count => $bit) {
|
126
|
if (strpos($bit, '%') === 0) {
|
127
|
$bits[$count] = $entity_id;
|
128
|
}
|
129
|
}
|
130
|
|
131
|
$bits[] = 'panelizer';
|
132
|
$bits[] = 'page_manager';
|
133
|
|
134
|
$base_path = implode('/', $bits);
|
135
|
if ($entity_handler->panelizer_access('settings', $entity, 'page_manager')) {
|
136
|
$links['settings'] = array(
|
137
|
'title' => t('Edit panelizer settings'),
|
138
|
'href' => "$base_path/settings",
|
139
|
);
|
140
|
}
|
141
|
if ($entity_handler->panelizer_access('context', $entity, 'page_manager')) {
|
142
|
$links['context'] = array(
|
143
|
'title' => t('Edit panelizer contexts'),
|
144
|
'href' => "$base_path/context",
|
145
|
);
|
146
|
}
|
147
|
if ($entity_handler->panelizer_access('layout', $entity, 'page_manager')) {
|
148
|
$links['layout'] = array(
|
149
|
'title' => t('Edit panelizer layout'),
|
150
|
'href' => "$base_path/layout",
|
151
|
);
|
152
|
}
|
153
|
if ($entity_handler->panelizer_access('content', $entity, 'page_manager')) {
|
154
|
$links['content'] = array(
|
155
|
'title' => t('Edit panelizer content'),
|
156
|
'href' => "$base_path/content",
|
157
|
);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
return $links;
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Callback to provide administrative summary of the task handler.
|
166
|
*/
|
167
|
function panelizer_panelizer_task_admin_summary($handler, $task, $subtask, $page, $show_title = TRUE) {
|
168
|
ctools_include('context');
|
169
|
ctools_include('context-task-handler');
|
170
|
|
171
|
$output = '';
|
172
|
|
173
|
$output .= '<div class="clear-block">';
|
174
|
if ($show_title) {
|
175
|
// Get the operations
|
176
|
$operations = page_manager_get_operations($page);
|
177
|
|
178
|
// Get operations for just this handler.
|
179
|
$operations = $operations['handlers']['children'][$handler->name]['children']['actions']['children'];
|
180
|
$args = array('handlers', $handler->name, 'actions');
|
181
|
$rendered_operations = page_manager_render_operations($page, $operations, array(), array('class' => array('actions')), 'actions', $args);
|
182
|
|
183
|
$output .= '<div class="handler-title clear-block">';
|
184
|
$output .= '<div class="actions handler-actions">' . $rendered_operations['actions'] . '</div>';
|
185
|
$output .= '<span class="title-label">' . t('Panelizer') . '</span>';
|
186
|
$output .= '</div>';
|
187
|
}
|
188
|
|
189
|
$plugin = page_manager_get_task_handler($handler->handler);
|
190
|
|
191
|
$object = ctools_context_handler_get_task_object($task, $subtask, $handler);
|
192
|
$context = ctools_context_load_contexts($object, TRUE);
|
193
|
|
194
|
$access = ctools_access_group_summary(!empty($handler->conf['access']) ? $handler->conf['access'] : array(), $context);
|
195
|
if ($access) {
|
196
|
$access = t('This variant will be selected if the entity being viewed is panelized AND @conditions. This variant must be enabled and selected for panelizer to work!', array('@conditions' => $access));
|
197
|
}
|
198
|
else {
|
199
|
$access = t('This variant will be selected if the entity being viewed is panelized. This variant must be enabled and selected for panelizer to work!');
|
200
|
}
|
201
|
|
202
|
$rows[] = array(
|
203
|
array(
|
204
|
'class' => array('page-summary-label'),
|
205
|
'data' => t('Selection rule'),
|
206
|
),
|
207
|
array(
|
208
|
'class' => array('page-summary-data'),
|
209
|
'data' => $access,
|
210
|
),
|
211
|
array('class' => array('page-summary-operation'), ''),
|
212
|
);
|
213
|
|
214
|
$output .= theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('page-manager-handler-summary'))));
|
215
|
$output .= '</div>';
|
216
|
|
217
|
return $output;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* Render a entity that has been panelized.
|
222
|
*/
|
223
|
function panelizer_panelizer_task_render($handler, $base_contexts, $args, $test = TRUE) {
|
224
|
// Get the context this is viewing; figure out what entity it is and load
|
225
|
// the right plugin.
|
226
|
ctools_include('context');
|
227
|
$context = _panelizer_panelizer_task_get_context($handler, $base_contexts);
|
228
|
if (!$context) {
|
229
|
return FALSE;
|
230
|
}
|
231
|
|
232
|
if (empty($context->data->panelizer['page_manager'])) {
|
233
|
return FALSE;
|
234
|
}
|
235
|
|
236
|
$panelizer = $context->data->panelizer['page_manager'];
|
237
|
// One of these two will always be set.
|
238
|
$entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type;
|
239
|
|
240
|
$address = implode('::', array('page_manager', $handler->task, $handler->subtask, $handler->name, implode('..', $args)));
|
241
|
|
242
|
if ($entity_handler = panelizer_entity_plugin_get_handler($entity_type)) {
|
243
|
$info = $entity_handler->render_entity($context->data, 'page_manager', NULL, $args, $address);
|
244
|
|
245
|
// Remove and add body element classes
|
246
|
$panel_body_css = &drupal_static('panel_body_css');
|
247
|
if (!empty($info['classes_array']) && !isset($panel_body_css['body_classes_to_add'])) {
|
248
|
$panel_body_css['body_classes_to_add'] = implode(' ', $info['classes_array']);
|
249
|
}
|
250
|
|
251
|
return $info;
|
252
|
}
|
253
|
}
|
254
|
|
255
|
/**
|
256
|
* Determine if the panelizer task handler should fire.
|
257
|
*
|
258
|
* This returns true if the configured entity is panelized and has
|
259
|
* a display.
|
260
|
*/
|
261
|
function panelizer_panelizer_task_test($handler, $base_contexts) {
|
262
|
if (empty($base_contexts)) {
|
263
|
return;
|
264
|
}
|
265
|
|
266
|
if (!ctools_context_handler_select($handler, $base_contexts)) {
|
267
|
return;
|
268
|
}
|
269
|
|
270
|
$context = _panelizer_panelizer_task_get_context($handler, $base_contexts);
|
271
|
if (empty($context->data)) {
|
272
|
return;
|
273
|
}
|
274
|
|
275
|
$entity = &$context->data;
|
276
|
// Fail if there isn't a panelizer object on the entity.
|
277
|
if (empty($entity->panelizer['page_manager']->display)) {
|
278
|
return;
|
279
|
}
|
280
|
|
281
|
$panelizer = $entity->panelizer['page_manager'];
|
282
|
$entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type;
|
283
|
|
284
|
$panelizer_handler = panelizer_entity_plugin_get_handler($entity_type);
|
285
|
if (!$panelizer_handler) {
|
286
|
return;
|
287
|
}
|
288
|
|
289
|
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
|
290
|
|
291
|
// Make sure the bundle + view mode is actually panelized!
|
292
|
return $panelizer_handler->is_panelized($bundle . '.page_manager');
|
293
|
}
|
294
|
|
295
|
function panelizer_panelizer_task_get_addressable($task, $subtask_name, $handler, $address, $contexts, $arguments, $type) {
|
296
|
ctools_include('plugins', 'panels');
|
297
|
if (empty($contexts)) {
|
298
|
return;
|
299
|
}
|
300
|
|
301
|
$context = _panelizer_panelizer_task_get_context($handler, $contexts);
|
302
|
if (empty($context->data)) {
|
303
|
return;
|
304
|
}
|
305
|
|
306
|
// Extract the entity from the context so we can load the panelizer.
|
307
|
$entity = &$context->data;
|
308
|
|
309
|
if (empty($entity->panelizer['page_manager']) || empty($entity->panelizer['page_manager']->display)) {
|
310
|
return;
|
311
|
}
|
312
|
|
313
|
// Load the panelizer info.
|
314
|
$panelizer = $entity->panelizer['page_manager'];
|
315
|
// Load the display.
|
316
|
$display = $panelizer->display;
|
317
|
|
318
|
// One of these two will always be set.
|
319
|
$entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type;
|
320
|
$handler = panelizer_entity_plugin_get_handler($entity_type);
|
321
|
if (!$handler) {
|
322
|
return;
|
323
|
}
|
324
|
|
325
|
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
|
326
|
|
327
|
$display->context = $handler->get_contexts($panelizer, $entity);
|
328
|
$display->args = $arguments;
|
329
|
$display->css_id = $panelizer->css_id;
|
330
|
|
331
|
$display->cache_key = implode(':', array('panelizer', $entity_type, $entity_id));
|
332
|
|
333
|
$renderer = panels_get_renderer($panelizer->pipeline, $display);
|
334
|
$renderer->prepare();
|
335
|
|
336
|
$pid = array_shift($address);
|
337
|
if (!empty($renderer->prepared['panes'][$pid])) {
|
338
|
if ($type == 'content') {
|
339
|
return $renderer->render_pane($renderer->prepared['panes'][$pid]);
|
340
|
}
|
341
|
elseif ($type == 'pane') {
|
342
|
return $renderer->prepared['panes'][$pid];
|
343
|
}
|
344
|
}
|
345
|
}
|
346
|
|
347
|
/**
|
348
|
* General settings for the panel
|
349
|
*/
|
350
|
function panelizer_panelizer_task_edit_settings($form, &$form_state) {
|
351
|
ctools_include('context');
|
352
|
ctools_include('context-task-handler');
|
353
|
$conf = $form_state['handler']->conf;
|
354
|
|
355
|
$form['title'] = array(
|
356
|
'#type' => 'textfield',
|
357
|
'#default_value' => !empty($conf['title']) ? $conf['title'] : t('Panelizer'),
|
358
|
'#title' => t('Administrative title'),
|
359
|
'#description' => t('Administrative title of this variant.'),
|
360
|
);
|
361
|
|
362
|
$contexts = ctools_context_handler_get_all_contexts($form_state['task'], $form_state['subtask'], $form_state['handler']);
|
363
|
|
364
|
$required_context = new ctools_context_required(t('Panelized entity'), 'entity');
|
365
|
$form['context'] = ctools_context_selector($contexts, $required_context, isset($conf['context']) ? $conf['context'] : '');
|
366
|
|
367
|
return $form;
|
368
|
}
|
369
|
|
370
|
function panelizer_panelizer_task_edit_settings_submit($form, &$form_state) {
|
371
|
$form_state['handler']->conf['title'] = $form_state['values']['title'];
|
372
|
$form_state['handler']->conf['context'] = $form_state['values']['context'];
|
373
|
}
|
374
|
|
375
|
/**
|
376
|
* Set up a title for the panel based upon the selection rules.
|
377
|
*/
|
378
|
function panelizer_panelizer_task_title($handler, $task, $subtask) {
|
379
|
if (isset($handler->conf['title'])) {
|
380
|
return check_plain($handler->conf['title']);
|
381
|
}
|
382
|
else {
|
383
|
return t('Panelizer');
|
384
|
}
|
385
|
}
|