Revision e5e66f93
Added by Assos Assos over 8 years ago
drupal7/sites/all/modules/panelizer/plugins/task_handlers/panelizer_node.inc | ||
---|---|---|
82 | 82 |
* Figure out the correct context to use for this panelizer. |
83 | 83 |
*/ |
84 | 84 |
function _panelizer_panelizer_task_get_context($handler, $contexts) { |
85 |
if (isset($handler->conf['context']) && !empty($contexts[$handler->conf['context']])) { |
|
85 |
$contexts = ctools_context_handler_get_handler_contexts($contexts, $handler); |
|
86 |
|
|
87 |
if (isset($handler->conf['context']) && is_string($handler->conf['context']) && !empty($contexts[$handler->conf['context']])) { |
|
86 | 88 |
return $contexts[$handler->conf['context']]; |
87 | 89 |
} |
88 | 90 |
|
... | ... | |
93 | 95 |
} |
94 | 96 |
|
95 | 97 |
// Fail! |
96 |
return stdClass(); |
|
98 |
return new stdClass(); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Get extra contexts to pass from page manager to panelizer. |
|
103 |
* |
|
104 |
* @param $handler |
|
105 |
* The handler object. |
|
106 |
* @param $base_contexts |
|
107 |
* The base contexts from page manager. |
|
108 |
* |
|
109 |
* @return array |
|
110 |
* All contexts defined in page manager other than the panelized entity |
|
111 |
* context. |
|
112 |
*/ |
|
113 |
function _panelizer_panelizer_task_get_extra_contexts($handler, $base_contexts) { |
|
114 |
$extra_contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler); |
|
115 |
|
|
116 |
// Remove the panelized context to prevent duplication in the extra contexts. |
|
117 |
if (isset($handler->conf['context']) && !empty($extra_contexts[$handler->conf['context']])) { |
|
118 |
unset($extra_contexts[$handler->conf['context']]); |
|
119 |
} |
|
120 |
elseif (!empty($extra_contexts)) { |
|
121 |
array_shift($extra_contexts); |
|
122 |
} |
|
123 |
|
|
124 |
return $extra_contexts; |
|
97 | 125 |
} |
98 | 126 |
|
99 | 127 |
/** |
100 |
* Provide appropriate contextual links for Panelizer controled entities. |
|
128 |
* Provide appropriate contextual links for Panelizer controlled entities.
|
|
101 | 129 |
*/ |
102 | 130 |
function panelizer_panelizer_task_contextual_link($handler, $plugin, $contexts, $args) { |
103 | 131 |
$links = array(); |
... | ... | |
109 | 137 |
|
110 | 138 |
$entity = &$context->data; |
111 | 139 |
|
112 |
if (empty($entity->panelizer['page_manager'])) { |
|
140 |
// Only show links for this view mode. |
|
141 |
$view_mode = 'page_manager'; |
|
142 |
|
|
143 |
if (empty($entity->panelizer[$view_mode])) { |
|
113 | 144 |
return FALSE; |
114 | 145 |
} |
115 | 146 |
|
116 |
$panelizer = $entity->panelizer['page_manager'];
|
|
147 |
$panelizer = $entity->panelizer[$view_mode];
|
|
117 | 148 |
// One of these two will always be set. |
118 | 149 |
$entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type; |
119 | 150 |
|
... | ... | |
129 | 160 |
} |
130 | 161 |
|
131 | 162 |
$bits[] = 'panelizer'; |
132 |
$bits[] = 'page_manager';
|
|
163 |
$bits[] = $view_mode;
|
|
133 | 164 |
|
134 | 165 |
$base_path = implode('/', $bits); |
135 |
if ($entity_handler->panelizer_access('settings', $entity, 'page_manager')) {
|
|
166 |
if ($entity_handler->panelizer_access('settings', $entity, $view_mode)) {
|
|
136 | 167 |
$links['settings'] = array( |
137 |
'title' => t('Edit panelizer settings'),
|
|
168 |
'title' => t("Edit custom display settings"),
|
|
138 | 169 |
'href' => "$base_path/settings", |
139 | 170 |
); |
140 | 171 |
} |
141 |
if ($entity_handler->panelizer_access('context', $entity, 'page_manager')) {
|
|
172 |
if ($entity_handler->panelizer_access('context', $entity, $view_mode)) {
|
|
142 | 173 |
$links['context'] = array( |
143 |
'title' => t('Edit panelizer contexts'),
|
|
174 |
'title' => t('Edit custom display contexts'),
|
|
144 | 175 |
'href' => "$base_path/context", |
145 | 176 |
); |
146 | 177 |
} |
147 |
if ($entity_handler->panelizer_access('layout', $entity, 'page_manager')) {
|
|
178 |
if ($entity_handler->panelizer_access('layout', $entity, $view_mode)) {
|
|
148 | 179 |
$links['layout'] = array( |
149 |
'title' => t('Edit panelizer layout'),
|
|
180 |
'title' => t('Edit custom display layout'),
|
|
150 | 181 |
'href' => "$base_path/layout", |
151 | 182 |
); |
152 | 183 |
} |
153 |
if ($entity_handler->panelizer_access('content', $entity, 'page_manager')) {
|
|
184 |
if ($entity_handler->panelizer_access('content', $entity, $view_mode)) {
|
|
154 | 185 |
$links['content'] = array( |
155 |
'title' => t('Edit panelizer content'),
|
|
186 |
'title' => t('Edit custom display content'),
|
|
156 | 187 |
'href' => "$base_path/content", |
157 | 188 |
); |
158 | 189 |
} |
190 |
|
|
191 |
// Work out what the default display is called. |
|
192 |
$default_display_name = $entity_handler->get_default_display_default_name($bundle, $view_mode); |
|
193 |
// If the default display is defined, add links to edit it. |
|
194 |
if (!empty($default_display_name)) { |
|
195 |
$template_base_path = "admin/structure/types/manage/{$bundle}/panelizer/{$view_mode}/{$default_display_name}"; |
|
196 |
if ($entity_handler->panelizer_access('settings', $entity, $view_mode)) { |
|
197 |
$links['default_settings'] = array( |
|
198 |
'title' => t('Edit default display settings'), |
|
199 |
'href' => "$template_base_path/settings", |
|
200 |
); |
|
201 |
} |
|
202 |
if ($entity_handler->panelizer_access('context', $entity, $view_mode)) { |
|
203 |
$links['default_context'] = array( |
|
204 |
'title' => t('Edit default display contexts'), |
|
205 |
'href' => "$template_base_path/context", |
|
206 |
); |
|
207 |
} |
|
208 |
if ($entity_handler->panelizer_access('layout', $entity, $view_mode)) { |
|
209 |
$links['default_layout'] = array( |
|
210 |
'title' => t('Edit default display layout'), |
|
211 |
'href' => "$template_base_path/layout", |
|
212 |
); |
|
213 |
} |
|
214 |
if ($entity_handler->panelizer_access('content', $entity, $view_mode)) { |
|
215 |
$links['default_content'] = array( |
|
216 |
'title' => t('Edit default display content'), |
|
217 |
'href' => "$template_base_path/content", |
|
218 |
); |
|
219 |
} |
|
220 |
} |
|
159 | 221 |
} |
160 | 222 |
|
161 | 223 |
return $links; |
... | ... | |
240 | 302 |
$address = implode('::', array('page_manager', $handler->task, $handler->subtask, $handler->name, implode('..', $args))); |
241 | 303 |
|
242 | 304 |
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']); |
|
305 |
$extra_contexts = _panelizer_panelizer_task_get_extra_contexts($handler, $base_contexts); |
|
306 |
$info = $entity_handler->render_entity($context->data, 'page_manager', NULL, $args, $address, $extra_contexts); |
|
307 |
|
|
308 |
// Add body element classes, appending to the existing value. |
|
309 |
$panel_body_css = &drupal_static('panel_body_css', array()); |
|
310 |
if (!empty($info['classes_array'])){ |
|
311 |
$panel_body_css += array('body_classes_to_add' => ''); |
|
312 |
$panel_body_css['body_classes_to_add'] = trim($panel_body_css['body_classes_to_add'] . ' ' . implode(' ', $info['classes_array'])); |
|
249 | 313 |
} |
250 | 314 |
|
251 | 315 |
return $info; |
... | ... | |
259 | 323 |
* a display. |
260 | 324 |
*/ |
261 | 325 |
function panelizer_panelizer_task_test($handler, $base_contexts) { |
262 |
if (empty($base_contexts)) { |
|
263 |
return; |
|
264 |
} |
|
326 |
ctools_include('context'); |
|
265 | 327 |
|
266 | 328 |
if (!ctools_context_handler_select($handler, $base_contexts)) { |
267 | 329 |
return; |
... | ... | |
358 | 420 |
'#title' => t('Administrative title'), |
359 | 421 |
'#description' => t('Administrative title of this variant.'), |
360 | 422 |
); |
423 |
$name = isset($conf['name']) ? $conf['name'] : FALSE; |
|
424 |
$form['name'] = array( |
|
425 |
'#type' => 'machine_name', |
|
426 |
'#title' => t('Machine name'), |
|
427 |
'#required' => FALSE, |
|
428 |
'#default_value' => $name, |
|
429 |
'#description' => t("A unique machine-readable name for this variant. It must only contain lowercase letters, numbers, and underscores. This name will be used when exporting the variant. If left empty the variant's name will be used instead."), |
|
430 |
'#size' => 32, |
|
431 |
'#maxlength' => 32, |
|
432 |
'#machine_name' => array( |
|
433 |
'exists' => 'page_manager_handler_check_machine_name', |
|
434 |
'source' => array('title'), |
|
435 |
), |
|
436 |
'#field_prefix' => '<span dir="ltr">' . $form_state['task_name'] . '__', |
|
437 |
'#field_suffix' => '</span>‎', |
|
438 |
); |
|
361 | 439 |
|
362 | 440 |
$contexts = ctools_context_handler_get_all_contexts($form_state['task'], $form_state['subtask'], $form_state['handler']); |
363 | 441 |
|
... | ... | |
368 | 446 |
} |
369 | 447 |
|
370 | 448 |
function panelizer_panelizer_task_edit_settings_submit($form, &$form_state) { |
449 |
$machine_name = $form_state['handler']->name; |
|
450 |
$name = $form_state['task_id'] . '__' . $form_state['values']['name']; |
|
451 |
|
|
452 |
// If new name doesn't equal machine name, we need to update and redirect. |
|
453 |
if ($machine_name !== $name) { |
|
454 |
$form_state['new trail'] = $form_state['trail']; |
|
455 |
$delta = array_search($machine_name, $form_state['new trail']); |
|
456 |
$form_state['new trail'][$delta] = $name; |
|
457 |
$form_state['handler']->name = $name; |
|
458 |
} |
|
459 |
|
|
371 | 460 |
$form_state['handler']->conf['title'] = $form_state['values']['title']; |
461 |
$form_state['handler']->conf['name'] = $form_state['values']['name']; |
|
372 | 462 |
$form_state['handler']->conf['context'] = $form_state['values']['context']; |
373 | 463 |
} |
374 | 464 |
|
375 | 465 |
/** |
376 |
* Set up a title for the panel based upon the selection rules.
|
|
466 |
* Set up a title for the display based upon the selection rules.
|
|
377 | 467 |
*/ |
378 | 468 |
function panelizer_panelizer_task_title($handler, $task, $subtask) { |
379 | 469 |
if (isset($handler->conf['title'])) { |
Also available in: Unified diff
Weekly update of contrib modules