| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * 6 * This is the task handler plugin to handle attaching a panel to any 7 * task that advertises itself as a 'context' type, which all of the 8 * basic page tasks provided by page_manager.module do by default. 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 'visible' => TRUE, // may be added up front. 17 18 // Administrative fields. 19 'title' => t('Panel'), 20 'admin summary' =>'panels_panel_context_admin_summary', 21 'admin title' => 'panels_panel_context_title', 22 'operations' => array( 23 'settings' => array( 24 'title' => t('General'), 25 'description' => t('Change general settings about this variant.'), 26 'form' => 'panels_panel_context_edit_settings', 27 ), 28 'criteria' => array( 29 'title' => t('Selection rules'), 30 'description' => t('Control the criteria used to decide whether or not this variant is used.'), 31 'ajax' => FALSE, 32 'form' => array( 33 'order' => array( 34 'form' => t('Selection rules'), 35 ), 36 'forms' => array( 37 'form' => array( 38 'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc', 39 'form id' => 'ctools_context_handler_edit_criteria', 40 ), 41 ), 42 ), 43 ), 44 'context' => array( 45 'title' => t('Contexts'), 46 'ajax' => FALSE, 47 'description' => t('Add additional context objects to this variant that can be used by the content.'), 48 'form' => array( 49 'order' => array( 50 'form' => t('Context'), 51 ), 52 'forms' => array( 53 'form' => array( 54 'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc', 55 'form id' => 'ctools_context_handler_edit_context', 56 ), 57 ), 58 ), 59 ), 60 'layout' => array( 61 'title' => t('Layout'), 62 'description' => t('Change the layout of this panel.'), 63 // No AJAX so we get our CSS loaded. 64 'ajax' => FALSE, 65 'form' => array( 66 'order' => array( 67 'choose' => t('Change layout'), 68 'move' => t('Move content from old layout'), 69 ), 70 'forms' => array( 71 'choose' => array( 72 'form id' => 'panels_panel_context_edit_layout', 73 ), 74 'move' => array( 75 'include' => array( 76 drupal_get_path('module', 'panels') . '/includes/display-layout.inc', 77 ), 78 'form id' => 'panels_panel_context_edit_move', 79 'submit' => 'panels_change_layout_submit', 80 ), 81 ), 82 ), 83 ), 84 'content' => array( 85 'title' => t('Content'), 86 'description' => t('Add content items and change their location with a drag and drop interface.'), 87 'ajax' => FALSE, 88 'form' => array( 89 'order' => array( 90 'form' => t('Content'), 91 ), 92 'forms' => array( 93 'form' => array( 94 'include' => array( 95 drupal_get_path('module', 'panels') . '/includes/display-edit.inc', 96 ), 97 'form id' => 'panels_panel_context_edit_content', 98 'no blocks' => TRUE, 99 ), 100 ), 101 ), 102 ), 103 'preview' => array( 104 'title' => t('Preview'), 105 'description' => t('Get a preview of what this variant will look like.'), 106 'form' => 'panels_panel_context_edit_preview', 107 'ajax' => FALSE, 108 'silent' => TRUE, 109 'form info' => array('finish text' => t('Preview')), 110 'no update and save' => TRUE, 111 ), 112 ), 113 114 'tab operation' => 'panels_panel_context_tab_operation', 115 116 // Callback to render the data. 117 'render' => 'panels_panel_context_render', 118 119 // Various callbacks for operations performed on the handler to ensure 120 // related data is updated properly. 121 'save' => 'panels_panel_context_save', 122 'delete' => 'panels_panel_context_delete', 123 'export' => 'panels_panel_context_export', 124 'clone' => 'panels_panel_context_clone', 125 126 'add features' => array( 127 'criteria' => t('Selection rules'), 128 'context' => t('Contexts'), 129 ), 130 // Where to go when finished. 131 'add finish' => 'content', 132 133 'required forms' => array( 134 'choose' => t('Choose layout'), 135 'settings' => t('Panel settings'), 136 'content' => t('Panel content'), 137 ), 138 139 'edit forms' => array( 140 'content' => t('Panel content'), 141 'criteria' => t('Selection rules'), 142 'settings' => t('General'), 143 'context' => t('Contexts'), 144 'layout' => t('Change layout'), 145 'move' => '', // no title makes it a 'hidden' edit form. 146 ), 147 'forms' => array( 148 'settings' => array( 149 'form id' => 'panels_panel_context_edit_settings', 150 ), 151 'choose' => array( 152 'form id' => 'panels_panel_context_edit_choose', 153 'no back validate' => TRUE, 154 ), 155 'layout' => array( 156 'no return' => TRUE, 157 'form id' => 'panels_panel_context_edit_layout', 158 ), 159 'move' => array( 160 'include' => array( 161 drupal_get_path('module', 'panels') . '/includes/display-layout.inc', 162 ), 163 'form id' => 'panels_panel_context_edit_move', 164 'submit' => 'panels_change_layout_submit', 165 ), 166 'content' => array( 167 'include' => array( 168 drupal_get_path('module', 'panels') . '/includes/display-edit.inc', 169 ), 170 'form id' => 'panels_panel_context_edit_content', 171 'no blocks' => TRUE, 172 ), 173 'context' => array( 174 'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc', 175 'form id' => 'ctools_context_handler_edit_context', 176 ), 177 'criteria' => array( 178 'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc', 179 'form id' => 'ctools_context_handler_edit_criteria', 180 ), 181 ), 182 'default conf' => array( 183 'title' => t('Panel'), 184 'no_blocks' => FALSE, 185 'pipeline' => 'standard', 186 'css_id' => '', 187 'css' => '', 188 'contexts' => array(), 189 'relationships' => array(), 190 ), 191 ); 192 193 /** 194 * Provide the operation trail for the 'Edit panel' link. 195 * 196 * When editing the panel, go directly to the content tab. 197 */ 198 function panels_panel_context_tab_operation($handler, $contexts, $args) { 199 return array('handlers', $handler->name, 'content'); 200 } 201 202 /** 203 * Get the display for a task handler. 204 * 205 * There are three methods that the display can be found. 206 * - In the database. $handler->conf['did'] will be set in this case, 207 * and $handler->conf['display'] won't be. 208 * - In $handler->conf['display'], with $handler->conf['did'] empty. This 209 * will be true for a default/imported task handler as well as a handler 210 * that has just been created but has not yet been saved. 211 * - in $handler->conf['display'] with $handler->conf['did' populated. This 212 * simply means that the display has been modified and is awaiting 213 * save. The modified one should always be used for editing purposes. 214 * - If none of the above is true, then a new display needs to be created 215 * for the handler and pla 216 */ 217 function &panels_panel_context_get_display(&$handler) { 218 if (isset($handler->conf['display'])) { 219 return $handler->conf['display']; 220 } 221 222 if (isset($handler->conf['did'])) { 223 $handler->conf['display'] = panels_load_display($handler->conf['did']); 224 225 // Check for a valid display. If no valid display can be loaded, something 226 // is wrong and we'll create a new one. 227 if (!empty($handler->conf['display'])) { 228 return $handler->conf['display']; 229 } 230 } 231 232 $handler->conf['display'] = panels_new_display(); 233 234 return $handler->conf['display']; 235 } 236 237 /** 238 * Check selection rules and, if passed, render the contexts. 239 */ 240 function panels_panel_context_render($handler, $base_contexts, $args, $test = TRUE) { 241 // Go through arguments and see if they match. 242 ctools_include('context'); 243 ctools_include('context-task-handler'); 244 ctools_include('plugins', 'panels'); 245 246 // Add my contexts 247 $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler); 248 249 // Test. 250 if ($test && !ctools_context_handler_select($handler, $contexts)) { 251 return; 252 } 253 254 if (isset($handler->handler)) { 255 ctools_context_handler_pre_render($handler, $contexts, $args); 256 } 257 258 // Load the display 259 $display = panels_panel_context_get_display($handler); 260 261 $display->context = $contexts; 262 $display->args = $args; 263 $display->css_id = $handler->conf['css_id']; 264 $task_name = page_manager_make_task_name($handler->task, $handler->subtask); 265 266 $display->cache_key = 'panel_context:' . $task_name . ':' . $handler->name; 267 268 // Check to see if there is any CSS. 269 if (!empty($handler->conf['css'])) { 270 ctools_include('css'); 271 $css_id = 'panel_context:' . $handler->name; 272 $filename = ctools_css_retrieve($css_id); 273 if (!$filename) { 274 $filename = ctools_css_store($css_id, $handler->conf['css']); 275 } 276 ctools_css_add_css($filename); 277 } 278 279 // With an argument, this actually sets the display. 280 panels_get_current_page_display($display); 281 282 // Handle backward compatibility with the IPE checkbox. 283 if (empty($handler->conf['pipeline'])) { 284 $handler->conf['pipeline'] = !empty($handler->conf['use_ipe']) ? 'ipe' : 'standard'; 285 } 286 287 $renderer = panels_get_renderer($handler->conf['pipeline'], $display); 288 289 $info = array( 290 'content' => panels_render_display($display, $renderer), 291 'no_blocks' => !empty($handler->conf['no_blocks']), 292 ); 293 294 $info['title'] = $display->get_title(); 295 296 return $info; 297 } 298 299 /** 300 * Callback to allow the handler to react to being saved. 301 * 302 * When a handler with a display is saved, two things have to happen. 303 * First, we have to save the display so that it becomes a real display, 304 * not the fake one we started with. Second, we have to cache 305 * any CSS that the display is using. This CSS can get re-cached 306 * later if the file disappears, but it's imperative that we do it here 307 * to make sure that old, dirty CSS cache gets removed. 308 */ 309 function panels_panel_context_save(&$handler, $update) { 310 // Only save the display if we believe it has been modified. 311 if (isset($handler->conf['display'])) { 312 panels_save_display($handler->conf['display']); 313 $handler->conf['did'] = $handler->conf['display']->did; 314 unset($handler->conf['display']); 315 } 316 317 // Delete any previous CSS cache file. 318 ctools_include('css'); 319 ctools_css_clear('panel_context:' . $handler->name); 320 321 if (isset($page->conf['temp_layout'])) { 322 unset($page->conf['temp_layout']); 323 } 324 } 325 326 /** 327 * Special handling for exporting a panel task handler. 328 * 329 * When a panel is exported, we need to export the display separately 330 * rather than just letting its object be unpacked, which does not work 331 * very well. 332 */ 333 function panels_panel_context_export(&$handler, $indent) { 334 $display = panels_panel_context_get_display($handler); 335 foreach (array('display', 'did', 'css_cache', 'temp_layout') as $item) { 336 if (isset($handler->conf[$item])) { 337 unset($handler->conf[$item]); 338 } 339 } 340 341 $output = panels_export_display($display, $indent); 342 $output .= $indent . '$handler->conf[\'display\'] = $display' . ";\n"; 343 return $output; 344 } 345 346 /** 347 * When a handler is cloned, we have to clone the display. 348 */ 349 function panels_panel_context_clone(&$handler) { 350 $old_display = panels_panel_context_get_display($handler); 351 $code = panels_export_display($old_display); 352 eval($code); 353 foreach (array('display', 'did', 'css_cache', 'temp_layout') as $item) { 354 if (isset($handler->conf[$item])) { 355 unset($handler->conf[$item]); 356 } 357 } 358 $display->did = 'new'; 359 $handler->conf['display'] = $display; 360 } 361 362 /** 363 * Callback to delete the display when a handler is deleted. 364 */ 365 function panels_panel_context_delete(&$handler) { 366 if (!empty($handler->conf['did'])) { 367 panels_delete_display($handler->conf['did']); 368 } 369 } 370 371 /** 372 * Set up a title for the panel based upon the selection rules. 373 */ 374 function panels_panel_context_title($handler, $task, $subtask) { 375 if (isset($handler->conf['title'])) { 376 return check_plain($handler->conf['title']); 377 } 378 else { 379 return t('Panel'); 380 } 381 } 382 383 /** 384 * Provide a nice little summary of what's in a panel. 385 * 386 * The task handler manager provides a summary of a given handler in a 387 * collapsible div. This callback provides that. For a Panel, we 388 * provide a summary of the layout type and content on one side, and 389 * a summary of the contexts in use on the other. 390 */ 391 function panels_panel_context_admin_summary($handler, $task, $subtask, $page, $show_title = TRUE) { 392 $task_name = page_manager_make_task_name($task['name'], $subtask['name']); 393 $output = ''; 394 395 $display = panels_panel_context_get_display($handler); 396 397 ctools_include('plugins', 'panels'); 398 ctools_include('context'); 399 ctools_include('context-task-handler'); 400 401 // Get the operations 402 $operations = page_manager_get_operations($page); 403 404 // Get operations for just this handler. 405 $operations = $operations['handlers']['children'][$handler->name]['children']['actions']['children']; 406 $args = array('handlers', $handler->name, 'actions'); 407 $rendered_operations = page_manager_render_operations($page, $operations, array(), array('class' => 'actions'), 'actions', $args); 408 409 $layout = panels_get_layout($display->layout); 410 411 $plugin = page_manager_get_task_handler($handler->handler); 412 413 $object = ctools_context_handler_get_task_object($task, $subtask, $handler); 414 $display->context = ctools_context_load_contexts($object, TRUE); 415 416 $access = ctools_access_group_summary(!empty($handler->conf['access']) ? $handler->conf['access'] : array(), $display->context); 417 if ($access) { 418 $access = t('This panel will be selected if @conditions.', array('@conditions' => $access)); 419 } 420 else { 421 $access = t('This panel will always be selected.'); 422 } 423 424 $rows = array(); 425 426 $type = $handler->type == t('Default') ? t('In code') : $handler->type; 427 $rows[] = array( 428 array('class' => t('page-summary-label'), 'data' => t('Storage')), 429 array('class' => t('page-summary-data'), 'data' => $type), 430 array('class' => t('page-summary-operation'), 'data' => ''), 431 ); 432 433 if (!empty($handler->disabled)) { 434 $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'enable'))); 435 $text = t('Disabled'); 436 } 437 else { 438 $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'disable'))); 439 $text = t('Enabled'); 440 } 441 442 $rows[] = array( 443 array('class' => t('page-summary-label'), 'data' => t('Status')), 444 array('class' => t('page-summary-data'), 'data' => $text), 445 array('class' => t('page-summary-operation'), 'data' => $link), 446 ); 447 448 $link = l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'criteria'))); 449 $rows[] = array( 450 array('class' => t('page-summary-label'), 'data' => t('Selection rule')), 451 array('class' => t('page-summary-data'), 'data' => $access), 452 array('class' => t('page-summary-operation'), 'data' => $link), 453 ); 454 455 $link = l(t('Change layout'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'layout'))); 456 $link .= '<br />' . l(t('Edit content'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'content'))); 457 $link .= '<br />' . l(t('Preview'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'preview'))); 458 $rows[] = array( 459 array('class' => t('page-summary-label'), 'data' => t('Layout')), 460 array('class' => t('page-summary-data'), 'data' => check_plain($layout['title'])), 461 array('class' => t('page-summary-operation'), 'data' => $link), 462 ); 463 464 $content_link = ' [' . l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'content'))) . ']'; 465 $context_link = ' [' . l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'context'))) . ']'; 466 467 $info = theme('table', array(), $rows, array('class' => 'page-manager-handler-summary')); 468 469 /* 470 $content = theme('panels_common_content_list', $display); 471 if (empty($contents)) { 472 $contents = t('This panel has no content.'); 473 } 474 $contexts = theme('ctools_context_list_no_table', $object); 475 if (empty($contexts)) { 476 $contexts = t('This panel has no contexts.'); 477 } 478 */ 479 480 $title = $handler->conf['title']; 481 if ($title != t('Panel')) { 482 $title = t('Panel: @title', array('@title' => $title)); 483 } 484 485 $output .= '<div class="clear-block">'; 486 if ($show_title) { 487 $output .= '<div class="handler-title clear-block">'; 488 $output .= '<div class="actions handler-actions">' . $rendered_operations['actions'] . '</div>'; 489 $output .= '<span class="title-label">' . $title . '</span>'; 490 } 491 492 $output .= '</div>'; 493 $output .= $info; 494 $output .= '</div>'; 495 /* 496 $output .= '<div class="right-container">'; 497 $output .= '<h3 class="context-title">' . t('Contexts') . $context_link . '</h3>'; 498 $output .= $contexts; 499 $output .= '</div>'; 500 501 $output .= '<div class="left-container">'; 502 // $output .= $icon; 503 $output .= '<h3 class="handler-title">' . t('Content') . $content_link . '</h3>'; 504 $output .= $content; 505 $output .= '</div>'; 506 */ 507 return $output; 508 } 509 510 // -------------------------------------------------------------------------- 511 // Forms 512 513 /** 514 * General notes about forms: The handler is automatically cached by the form 515 * wizard, so anything we store on $form_state['handler'] anywhere will get 516 * saved and appear on the next form. The cache is a 'working' cache and 517 * if the user hits cancel on any page of the multi-page wizard, all 518 * changes since the last 'update/finish' click will be flushed away. 519 * 520 * Many of the Panels forms call through to the real Panels cousins. These 521 * forms are smart enough to know that they're being wrapped in another 522 * form and act appropriately. Some of them are so smart that we just let 523 * their submit and validate handlers do the work rather than writing 524 * additional ones here. 525 */ 526 527 /** 528 * Choose a layout for this panel. 529 * 530 * This is only called during 'add', when we know that there isn't a 531 * previous layout to choose from. a different, only slightly different 532 * variant is called to change a pre-existing layout. 533 */ 534 function panels_panel_context_edit_choose(&$form, &$form_state) { 535 ctools_include('common', 'panels'); 536 ctools_include('display-layout', 'panels'); 537 ctools_include('plugins', 'panels'); 538 539 // @todo -- figure out where/how to deal with this. 540 $form_state['allowed_layouts'] = 'panels_page'; 541 542 $form_state['display'] = &panels_panel_context_get_display($form_state['handler']); 543 544 // Tell the Panels form not to display buttons. 545 $form_state['no buttons'] = TRUE; 546 547 // Change the #id of the form so the CSS applies properly. 548 $form['#id'] = 'panels-choose-layout'; 549 $form = array_merge($form, panels_choose_layout($form_state)); 550 } 551 552 /** 553 * Validate that a layout was chosen. 554 */ 555 function panels_panel_context_edit_choose_validate(&$form, &$form_state) { 556 if (empty($form_state['values']['layout'])) { 557 form_error($form['layout'], t('You must select a layout.')); 558 } 559 } 560 561 /** 562 * A layout has been selected, set it up. 563 */ 564 function panels_panel_context_edit_choose_submit(&$form, &$form_state) { 565 $form_state['display']->layout = $form_state['values']['layout']; 566 $form_state['handler']->conf['display'] = $form_state['display']; 567 if (isset($form_state['page']->display_cache[$form_state['handler_id']])) { 568 $form_state['page']->display_cache[$form_state['handler_id']]->display = $form_state['display']; 569 } 570 } 571 572 /** 573 * Change the layout for this panel. 574 * 575 * This form is only used if a layout already exists and the user wants 576 * to change to a different one. The submit handler changes the next form 577 * to the move content form, which is 'hidden' so it won't be accessed 578 * directly. 579 */ 580 function panels_panel_context_edit_layout(&$form, &$form_state) { 581 ctools_include('common', 'panels'); 582 ctools_include('display-layout', 'panels'); 583 ctools_include('plugins', 'panels'); 584 585 // @todo -- figure out where/how to deal with this. 586 $form_state['allowed_layouts'] = 'panels_page'; 587 588 $form_state['display'] = &panels_panel_context_get_display($form_state['handler']); 589 590 // Tell the Panels form not to display buttons. 591 $form_state['no buttons'] = TRUE; 592 593 // Change the #id of the form so the CSS applies properly. 594 $form['#id'] = 'panels-choose-layout'; 595 $form = array_merge($form, panels_choose_layout($form_state)); 596 } 597 598 /** 599 * Validate that a layout was chosen. 600 */ 601 function panels_panel_context_edit_layout_validate(&$form, &$form_state) { 602 $display = &panels_panel_context_get_display($form_state['handler']); 603 604 if (empty($form_state['values']['layout'])) { 605 form_error($form['layout'], t('You must select a layout.')); 606 } 607 if ($form_state['values']['layout'] == $display->layout) { 608 form_error($form['layout'], t('You must select a different layout if you wish to change layouts.')); 609 } 610 } 611 612 /** 613 * A layout has been selected, set it up. 614 */ 615 function panels_panel_context_edit_layout_submit(&$form, &$form_state) { 616 $display = &panels_panel_context_get_display($form_state['handler']); 617 618 if ($form_state['values']['layout'] != $display->layout) { 619 $form_state['handler']->conf['temp_layout'] = $form_state['values']['layout']; 620 } 621 } 622 623 /** 624 * When a layout is changed, the user is given the opportunity to move content. 625 */ 626 function panels_panel_context_edit_move(&$form, &$form_state) { 627 $form_state['display'] = &panels_panel_context_get_display($form_state['handler']); 628 $form_state['layout'] = $form_state['handler']->conf['temp_layout']; 629 630 ctools_include('common', 'panels'); 631 ctools_include('display-layout', 'panels'); 632 ctools_include('plugins', 'panels'); 633 634 // Tell the Panels form not to display buttons. 635 $form_state['no buttons'] = TRUE; 636 637 // Change the #id of the form so the CSS applies properly. 638 $form = array_merge($form, panels_change_layout($form_state)); 639 640 // Change the 'back' button to just go directly to the previous form 641 // $task_id = $form_state['task']['name']; 642 // $handler_id = $form_state['handler']->handler; 643 // $name = $form_state['handler']->name; 644 645 // This form is outside the normal wizard list, so we need to specify the 646 // previous/next forms. 647 $form['buttons']['previous']['#next'] = 'layout'; 648 $form['buttons']['next']['#next'] = 'content'; 649 650 $form_state['form_info']['return path'] = page_manager_edit_url($form_state['page']->task_name, array('handlers', $form_state['handler_id'], 'content')); 651 } 652 653 /** 654 * Present the panels drag & drop editor to edit the display attached 655 * to the task handler. 656 */ 657 function panels_panel_context_edit_content(&$form, &$form_state) { 658 ctools_include('ajax'); 659 ctools_include('plugins', 'panels'); 660 ctools_include('common', 'panels'); 661 ctools_include('context'); 662 ctools_include('context-task-handler'); 663 664 $cache = panels_edit_cache_get('panel_context:' . $form_state['task_name'] . ':' . $form_state['handler_id']); 665 666 $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display); 667 $form_state['renderer']->cache = &$cache; 668 669 $form_state['display'] = &$cache->display; 670 $form_state['content_types'] = $cache->content_types; 671 // Tell the Panels form not to display buttons. 672 $form_state['no buttons'] = TRUE; 673 $form_state['display_title'] = !empty($cache->display_title); 674 $form_state['no preview'] = TRUE; 675 $form_state['page']->display_cache[$form_state['handler_id']] = $cache; 676 677 $form = array_merge($form, panels_edit_display_form($form_state)); 678 // Make sure the theme will work since our form id is different. 679 $form['#theme'] = 'panels_edit_display_form'; 680 681 if (!isset($form_state['type']) || $form_state['type'] != 'add' && !empty($form_state['handler_id']) && !empty($form['buttons'])) { 682 $form['buttons']['preview'] = $form['buttons']['return']; 683 $form['buttons']['preview']['#value'] = t('Update and preview'); 684 } 685 } 686 687 function panels_panel_context_edit_content_submit(&$form, &$form_state) { 688 panels_edit_display_form_submit($form, $form_state); 689 $handler = &$form_state['handler']; 690 691 // update the cached display: 692 $display = $form_state['page']->display_cache[$form_state['handler_id']]->display; 693 $handler->conf['display'] = $display; 694 unset($form_state['page']->display_cache[$form_state['handler_id']]); 695 696 if ($form_state['clicked_button']['#value'] == t('Update and preview')) { 697 $form_state['new trail'] = array('handlers', $form_state['handler_id'], 'preview'); 698 } 699 } 700 701 /** 702 * General settings for the panel 703 */ 704 function panels_panel_context_edit_settings(&$form, &$form_state) { 705 $conf = $form_state['handler']->conf; 706 $form['conf']['title'] = array( 707 '#type' => 'textfield', 708 '#default_value' => $conf['title'], 709 '#title' => t('Administrative title'), 710 '#description' => t('Administrative title of this variant.'), 711 ); 712 713 $form['conf']['no_blocks'] = array( 714 '#type' => 'checkbox', 715 '#default_value' => $conf['no_blocks'], 716 '#title' => t('Disable Drupal blocks/regions'), 717 '#description' => t('Check this to have the page disable all regions displayed in the theme. Note that some themes support this setting better than others. If in doubt, try with stock themes to see.'), 718 ); 719 720 ctools_include('plugins', 'panels'); 721 $pipelines = panels_get_renderer_pipelines(); 722 723 // Handle backward compatibility with the IPE checkbox. 724 if (empty($conf['pipeline'])) { 725 $conf['pipeline'] = !empty($conf['use_ipe']) ? 'ipe' : 'standard'; 726 } 727 728 // If there are no pipelines, that probably means we're operating in 729 // legacy mode. 730 if (empty($pipelines)) { 731 // We retain the original pipeline so we don't wreck things by installing 732 // old modules. 733 $form['conf']['pipeline'] = array( 734 '#type' => 'value', 735 '#value' => $conf['pipeline'], 736 ); 737 } 738 else { 739 $options = array(); 740 foreach ($pipelines as $name => $pipeline) { 741 $options[$name] = check_plain($pipeline->admin_title) . '<div class="description">' . check_plain($pipeline->admin_description) . '</div>'; 742 } 743 744 $form['conf']['pipeline'] = array( 745 '#type' => 'radios', 746 '#options' => $options, 747 '#title' => t('Renderer'), 748 '#default_value' => $conf['pipeline'], 749 ); 750 } 751 752 $form['conf']['css_id'] = array( 753 '#type' => 'textfield', 754 '#size' => 35, 755 '#default_value' => $conf['css_id'], 756 '#title' => t('CSS ID'), 757 '#description' => t('The CSS ID to apply to this page'), 758 ); 759 760 $form['conf']['css'] = array( 761 '#type' => 'textarea', 762 '#title' => t('CSS code'), 763 '#description' => t('Enter well-formed CSS code here; this code will be embedded into the page, and should only be used for minor adjustments; it is usually better to try to put CSS for the page into the theme if possible. This CSS will be filtered for safety so some CSS may not work.'), 764 '#default_value' => $conf['css'], 765 ); 766 } 767 768 /** 769 * Submit handler for general settings form. 770 */ 771 function panels_panel_context_edit_settings_submit(&$form, &$form_state) { 772 $form_state['handler']->conf['no_blocks'] = $form_state['values']['no_blocks']; 773 $form_state['handler']->conf['pipeline'] = $form_state['values']['pipeline']; 774 $form_state['handler']->conf['css_id'] = $form_state['values']['css_id']; 775 $form_state['handler']->conf['css'] = $form_state['values']['css']; 776 $form_state['handler']->conf['title'] = $form_state['values']['title']; 777 778 // Unset the old checkbox so we don't store needless data. 779 if (isset($form_state['handler']->conf['use_ipe'])) { 780 unset($form_state['handler']->conf['use_ipe']); 781 } 782 } 783 784 /** 785 * Form to show a nice preview. 786 */ 787 function panels_panel_context_edit_preview(&$form, &$form_state) { 788 ctools_include('context'); 789 ctools_include('context-task-handler'); 790 791 $contexts = ctools_context_handler_get_all_contexts($form_state['task'], $form_state['subtask'], $form_state['handler']); 792 $form['preview'] = array(); 793 ctools_context_replace_form($form['preview'], $contexts); 794 795 // automatically preview if there are no argument placeholders. 796 if (empty($form['preview'])) { 797 $display = panels_panel_context_get_display($form_state['handler']); 798 $display->context = $contexts; 799 $display->skip_cache = TRUE; 800 $output = panels_render_display($display); 801 if (isset($form['buttons'])) { 802 unset($form['buttons']); 803 } 804 } 805 else { 806 $form['preview']['#tree'] = TRUE; 807 $form_state['contexts'] = $contexts; 808 } 809 810 if (!empty($output)) { 811 $form['output'] = array( 812 '#value' => $output, 813 ); 814 } 815 816 $form_state['do not cache'] = TRUE; 817 } 818 819 /** 820 * Display a preview upon submit if arguments were needed. 821 */ 822 function panels_panel_context_edit_preview_submit(&$form, &$form_state) { 823 $display = panels_panel_context_get_display($form_state['handler']); 824 $display->context = ctools_context_replace_placeholders($form_state['contexts'], $form_state['values']['preview']); 825 826 $form_state['content'] = panels_render_display($display); 827 $form_state['redirect'] = FALSE; 828 $form_state['rerender'] = TRUE; 829 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |