| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: page.admin.inc,v 1.18.2.13 2010/08/30 22:07:52 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Administrative functions for the page subtasks. 7 * 8 * These are attached to the menu system in page.inc via the hook_menu 9 * delegation. They are included here so that this code is loaded 10 * only when needed. 11 */ 12 13 /** 14 * Delegated implementation of hook_menu(). 15 */ 16 function page_manager_page_menu(&$items, $task) { 17 // Set up access permissions. 18 $access_callback = isset($task['admin access callback']) ? $task['admin access callback'] : 'user_access'; 19 $access_arguments = isset($task['admin access arguments']) ? $task['admin access arguments'] : array('administer page manager'); 20 21 $base = array( 22 'access callback' => $access_callback, 23 'access arguments' => $access_arguments, 24 'file' => 'plugins/tasks/page.admin.inc', 25 ); 26 27 $items['admin/build/pages/add'] = array( 28 'title' => 'Add custom page', 29 'page callback' => 'page_manager_page_add_subtask', 30 'page arguments' => array(), 31 'type' => MENU_LOCAL_TASK, 32 ) + $base; 33 34 $items['admin/build/pages/import'] = array( 35 'title' => 'Import page', 36 'page callback' => 'drupal_get_form', 37 'page arguments' => array('page_manager_page_import_subtask', 'page'), 38 'type' => MENU_LOCAL_TASK, 39 ) + $base; 40 if ($access_callback == 'user_access') { 41 $items['admin/build/pages/import']['access callback'] = 'ctools_access_multiperm'; 42 $items['admin/build/pages/import']['access arguments'][] = 'use PHP for block visibility'; 43 } 44 45 // AJAX callbacks for argument modal. 46 $items['admin/build/pages/argument'] = array( 47 'page callback' => 'page_manager_page_subtask_argument_ajax', 48 'type' => MENU_CALLBACK, 49 ) + $base; 50 51 // Add menu entries for each subtask 52 foreach (page_manager_page_load_all() as $subtask_id => $subtask) { 53 if (!empty($subtask->disabled)) { 54 continue; 55 } 56 57 if (!isset($subtask->access['type'])) { 58 $subtask->access['type'] = 'none'; 59 } 60 if (!isset($subtask->access['settings'])) { 61 $subtask->access['settings'] = NULL; 62 } 63 64 $path = array(); 65 $page_arguments = array($subtask_id); 66 $access_arguments = array($subtask->access); 67 $load_arguments = array($subtask_id, '%index', '%map'); 68 69 // Replace named placeholders with our own placeholder to load contexts. 70 $position = 0; 71 72 foreach (explode('/', $subtask->path) as $bit) { 73 // Remove things like double slashes completely. 74 if (!isset($bit) || $bit === '') { 75 continue; 76 } 77 78 if ($bit[0] == '%' && $bit != '%') { 79 $placeholder = '%pm_arg'; 80 81 // Chop off that %. 82 $name = substr($bit, 1); 83 84 // Check to see if the argument plugin wants to use a different 85 // placholder. This will allow to_args. 86 if (!empty($subtask->arguments[$name])) { 87 ctools_include('context'); 88 if (!empty($subtask->arguments[$name]['name'])) { 89 $plugin = ctools_get_argument($subtask->arguments[$name]['name']); 90 if (isset($plugin['path placeholder'])) { 91 if (function_exists($plugin['path placeholder'])) { 92 $placeholder = $plugin['path placeholder']($subtask->arguments[$name]); 93 } 94 else { 95 $placeholder = $plugin['path placeholder']; 96 } 97 } 98 } 99 } 100 // If an argument, swap it out with our argument loader and make sure 101 // the argument gets passed through to the page callback. 102 $path[] = $placeholder; 103 $page_arguments[] = $position; 104 $access_arguments[] = $position; 105 } 106 else if ($bit[0] != '!') { 107 $path[] = $bit; 108 } 109 110 // Increment position. We do it like this to skip empty items that 111 // could happen from erroneous paths like: this///that 112 $position++; 113 } 114 115 $menu_path = implode('/', $path); 116 117 $items[$menu_path] = page_manager_page_menu_item($task, $subtask->menu, $access_arguments, $page_arguments, $load_arguments); 118 119 // Add a parent menu item if one is configured. 120 if (isset($subtask->menu['type']) && $subtask->menu['type'] == 'default tab' && $subtask->menu['parent']['type'] != 'none') { 121 array_pop($path); 122 $parent_path = implode('/', $path); 123 $items[$parent_path] = page_manager_page_menu_item($task, $subtask->menu['parent'], $access_arguments, $page_arguments, $load_arguments); 124 } 125 } 126 } 127 128 /** 129 * Create a menu item for page manager pages. 130 * 131 * @param $menu 132 * The configuration to use. It will contain a type, and depending on the 133 * type may also contain weight, title and name. These are presumed to have 134 * been configured from the UI. 135 * @param $access_arguments 136 * Arguments that go with ctools_access_menu; it should be loaded with 137 * the access plugin type, settings, and positions of any arguments that 138 * may produce contexts. 139 * @param $page_arguments 140 * This should be seeded with the subtask name for easy loading and like 141 * the access arguments above should contain positions of arguments so 142 * that the menu system passes contexts through. 143 * @param $load_arguments 144 * Arguments to send to the arg loader; should be the subtask id and '%index'. 145 */ 146 function page_manager_page_menu_item($task, $menu, $access_arguments, $page_arguments, $load_arguments) { 147 $item = array( 148 'access callback' => 'ctools_access_menu', 149 'access arguments' => $access_arguments, 150 'page callback' => 'page_manager_page_execute', 151 'page arguments' => $page_arguments, 152 'load arguments' => $load_arguments, 153 'file' => 'plugins/tasks/page.inc', 154 ); 155 156 if (isset($menu['title'])) { 157 $item['title'] = $menu['title']; 158 } 159 if (isset($menu['weight'])) { 160 $item['weight'] = $menu['weight']; 161 } 162 163 if (empty($menu['type'])) { 164 $menu['type'] = 'none'; 165 } 166 167 switch ($menu['type']) { 168 case 'none': 169 default: 170 $item['type'] = MENU_CALLBACK; 171 break; 172 173 case 'normal': 174 $item['type'] = MENU_NORMAL_ITEM; 175 // Insert item into the proper menu 176 $item['menu_name'] = $menu['name']; 177 break; 178 179 case 'tab': 180 $item['type'] = MENU_LOCAL_TASK; 181 break; 182 183 case 'default tab': 184 $item['type'] = MENU_DEFAULT_LOCAL_TASK; 185 break; 186 } 187 188 return $item; 189 } 190 191 /** 192 * Page callback to add a subtask. 193 */ 194 function page_manager_page_add_subtask($task_name = NULL, $step = NULL) { 195 ctools_include('context'); 196 $task = page_manager_get_task('page'); 197 $task_handler_plugins = page_manager_get_task_handler_plugins($task); 198 if (empty($task_handler_plugins)) { 199 drupal_set_message(t('There are currently no variants available and a page may not be added. Perhaps you need to install the Panels module to get a variant?'), 'error'); 200 return ' '; 201 } 202 203 $form_info = array( 204 'id' => 'page_manager_add_page', 205 'show trail' => TRUE, 206 'show back' => TRUE, 207 'show return' => FALSE, 208 'next callback' => 'page_manager_page_add_subtask_next', 209 'finish callback' => 'page_manager_page_add_subtask_finish', 210 'return callback' => 'page_manager_page_add_subtask_finish', 211 'cancel callback' => 'page_manager_page_add_subtask_cancel', 212 'add order' => array( 213 'basic' => t('Basic settings'), 214 'argument' => t('Argument settings'), 215 'access' => t('Access control'), 216 'menu' => t('Menu settings'), 217 ), 218 'forms' => array( 219 'basic' => array( 220 'form id' => 'page_manager_page_form_basic', 221 ), 222 'access' => array( 223 'form id' => 'page_manager_page_form_access', 224 ), 225 'menu' => array( 226 'form id' => 'page_manager_page_form_menu', 227 ), 228 'argument' => array( 229 'form id' => 'page_manager_page_form_argument', 230 ), 231 ), 232 ); 233 234 if ($task_name) { 235 $page = page_manager_get_page_cache($task_name); 236 if (empty($page)) { 237 return drupal_not_found(); 238 } 239 240 $form_info['path'] = "admin/build/pages/add/$task_name/%step"; 241 } 242 else { 243 $new_page = page_manager_page_new(); 244 $new_page->name = NULL; 245 246 $page = new stdClass(); 247 page_manager_page_new_page_cache($new_page, $page); 248 $form_info['path'] = 'admin/build/pages/add/%task_name/%step'; 249 } 250 251 if ($step && $step != 'basic') { 252 $handler_plugin = page_manager_get_task_handler($page->handler); 253 254 $form_info['forms'] += $handler_plugin['forms']; 255 256 if (isset($page->forms)) { 257 foreach ($page->forms as $id) { 258 if (isset($form_info['add order'][$id])) { 259 $form_info['order'][$id] = $form_info['add order'][$id]; 260 } 261 else if (isset($handler_plugin['add features'][$id])) { 262 $form_info['order'][$id] = $handler_plugin['add features'][$id]; 263 } 264 else if (isset($handler_plugin['required forms'][$id])) { 265 $form_info['order'][$id] = $handler_plugin['required forms'][$id]; 266 } 267 } 268 } 269 else { 270 $form_info['order'] = $form_info['add order']; 271 } 272 273 // This means we just submitted our form from the default list 274 // of steps, which we've traded in for a newly generated list of 275 // steps above. We need to translate this 'next' step into what 276 // our questions determined would be next. 277 if ($step == 'next') { 278 $keys = array_keys($form_info['order']); 279 // get rid of 'basic' from the list of forms. 280 array_shift($keys); 281 $step = array_shift($keys); 282 283 // If $step == 'basic' at this point, we were not presented with any 284 // additional forms at all. Let's just save and go! 285 if ($step == 'basic') { 286 page_manager_save_page_cache($page); 287 // Redirect to the new page's task handler editor. 288 drupal_goto(page_manager_edit_url($page->task_name)); 289 } 290 } 291 } 292 else { 293 $form_info['show trail'] = FALSE; 294 $form_info['order'] = array( 295 'basic' => t('Basic settings'), 296 'next' => t('A meaningless second page'), 297 ); 298 } 299 300 ctools_include('wizard'); 301 $form_state = array( 302 'task' => $task, 303 'subtask' => $page->subtask, 304 'page' => &$page, 305 'type' => 'add', 306 'task_id' => 'page', 307 'task_name' => $page->task_name, 308 'creating' => TRUE, 309 ); 310 311 if (!empty($page->handlers)) { 312 $keys = array_keys($page->handlers); 313 $key = array_shift($keys); 314 $form_state['handler'] = &$page->handlers[$key]; 315 $form_state['handler_id'] = $key; 316 } 317 318 $output = ctools_wizard_multistep_form($form_info, $step, $form_state); 319 320 if (!$output) { 321 // redirect. 322 drupal_redirect_form(array(), $form_state['redirect']); 323 } 324 325 return $output; 326 } 327 328 /** 329 * Callback generated when the add page process is finished. 330 */ 331 function page_manager_page_add_subtask_finish(&$form_state) { 332 $page = &$form_state['page']; 333 // Update the cache with changes. 334 page_manager_set_page_cache($page); 335 336 $handler = $form_state['handler']; 337 $handler_plugin = page_manager_get_task_handler($handler->handler); 338 339 // Redirect to the new page's task handler editor. 340 if (isset($handler_plugin['add finish'])) { 341 $form_state['redirect'] = page_manager_edit_url($page->task_name, array('handlers', $handler->name, $handler_plugin['add finish'])); 342 } 343 else { 344 $form_state['redirect'] = page_manager_edit_url($page->task_name); 345 } 346 return; 347 } 348 349 /** 350 * Callback generated when the 'next' button is clicked. 351 * 352 * All we do here is store the cache. 353 */ 354 function page_manager_page_add_subtask_next(&$form_state) { 355 if (empty($form_state['task_name']) || $form_state['task_name'] == 'page') { 356 // We may not have known the path to go next, because we didn't yet know the 357 // task name. This fixes that. 358 $form_state['form_info']['path'] = str_replace('%task_name', $form_state['page']->task_name, $form_state['form_info']['path']); 359 360 $form_state['redirect'] = ctools_wizard_get_path($form_state['form_info'], $form_state['clicked_button']['#next']); 361 } 362 363 // Update the cache with changes. 364 page_manager_set_page_cache($form_state['page']); 365 } 366 367 /** 368 * Callback generated when the 'cancel' button is clicked. 369 * 370 * All we do here is clear the cache. 371 */ 372 function page_manager_page_add_subtask_cancel(&$form_state) { 373 // Wipe all our stored changes. 374 if (isset($form_state['page']->task_name)) { 375 page_manager_clear_page_cache($form_state['page']->task_name); 376 } 377 } 378 379 /** 380 * Basic settings form for a page manager page. 381 */ 382 function page_manager_page_form_basic(&$form, &$form_state) { 383 $page = &$form_state['page']->subtask['subtask']; 384 $task = $form_state['task']; 385 386 $form['admin_title'] = array( 387 '#type' => 'textfield', 388 '#title' => t('Administrative title'), 389 '#description' => t('The name of this page. This will appear in the administrative interface to easily identify it.'), 390 '#default_value' => $page->admin_title, 391 ); 392 393 $form['name'] = array( 394 '#type' => 'textfield', 395 '#title' => t('Machine name'), 396 '#description' => t('The machine readable name of this page. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'), 397 '#default_value' => $page->name, 398 ); 399 400 if (isset($page->pid) || empty($form_state['creating'])) { 401 $form['name']['#disabled'] = TRUE; 402 $form['name']['#value'] = $page->name; 403 } 404 405 $form['admin_description'] = array( 406 '#type' => 'textarea', 407 '#title' => t('Administrative description'), 408 '#description' => t('A description of what this page is, does or is for, for administrative use.'), 409 '#default_value' => $page->admin_description, 410 ); 411 412 // path 413 $form['path'] = array( 414 '#type' => 'textfield', 415 '#title' => t('Path'), 416 '#description' => t('The URL path to get to this page. You may create named placeholders for variable parts of the path by using %name for required elements and !name for optional elements. For example: "node/%node/foo", "forum/%forum" or "dashboard/!input". These named placeholders can be turned into contexts on the arguments form.'), 417 '#default_value' => $page->path, 418 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), 419 ); 420 421 $frontpage = variable_get('site_frontpage', 'node'); 422 423 $path = array(); 424 if ($page->path) { 425 foreach (explode('/', $page->path) as $bit) { 426 if ($bit[0] != '!') { 427 $path[] = $bit; 428 } 429 } 430 } 431 432 $path = implode('/', $path); 433 434 if (empty($path) || $path != $frontpage) { 435 $form['frontpage'] = array( 436 '#type' => 'checkbox', 437 '#default_value' => !empty($page->make_frontpage), 438 '#title' => t('Make this your site home page.'), 439 '#description' => t('To set this panel as your home page you must create a unique path name with no % placeholders in the path. The site home page is currently set to %homepage on the !siteinfo configuration form.', array('!siteinfo' => l('Site Information', 'admin/settings/site-information'), '%homepage' => '/' . $frontpage)), 440 ); 441 } 442 else if ($path == $frontpage) { 443 $form['frontpage_markup'] = array( 444 '#value' => '<b>' . t('This page is currently set to be your site home page. This can be modified on the !siteinfo configuration form.', array('!siteinfo' => l('Site Information', 'admin/settings/site-information'))) . '</b>', 445 ); 446 447 $form['frontpage'] = array( 448 '#type' => 'value', 449 '#value' => TRUE, 450 ); 451 } 452 453 if (!isset($page->pid) && !empty($form_state['creating'])) { 454 $features['default'] = array( 455 'access' => t('Access control'), 456 'menu' => t('Visible menu item'), 457 ); 458 459 module_load_include('inc', 'page_manager', 'page_manager.admin'); 460 page_manager_handler_add_form($form, $form_state, $features); 461 } 462 463 } 464 465 function page_manager_page_form_basic_validate_filter($value) { 466 return $value === -1; 467 } 468 469 /** 470 * Validate the basic form. 471 */ 472 function page_manager_page_form_basic_validate(&$form, &$form_state) { 473 // Ensure path is unused by other pages. 474 $page = $form_state['page']->subtask['subtask']; 475 $name = !empty($form_state['values']['name']) ? $form_state['values']['name'] : $page->name; 476 if (empty($name)) { 477 form_error($form['name'], t('Name is required.')); 478 } 479 480 // If this is new, make sure the name is unique: 481 if (empty($page->name)) { 482 $test = page_manager_page_load($name); 483 if ($test) { 484 form_error($form['name'], t('That name is used by another page: @page', array('@page' => $test->admin_title))); 485 } 486 487 // Ensure name fits the rules: 488 if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) { 489 form_error($form['name'], t('Page name must be alphanumeric or underscores only.')); 490 } 491 } 492 493 $pages = page_manager_page_load_all(); 494 foreach ($pages as $test) { 495 if ($test->name != $name && $test->path == $form_state['values']['path'] && empty($test->disabled)) { 496 form_error($form['path'], t('That path is used by another page: @page', array('@page' => $test->admin_title))); 497 } 498 } 499 500 // Ensure path is unused by things NOT pages. We do the double check because 501 // we're checking against our page callback. 502 $path = array(); 503 if (empty($form_state['values']['path'])) { 504 form_error($form['path'], t('Path is required.')); 505 // stop processing here if there is no path. 506 return; 507 } 508 509 $found = FALSE; 510 $error = FALSE; 511 foreach (explode('/', $form_state['values']['path']) as $position => $bit) { 512 if (!isset($bit) || $bit === '') { 513 continue; 514 } 515 516 if ($bit == '%' || $bit == '!') { 517 form_error($form['path'], t('You cannot have an unnamed placeholder (% or ! by itself). Please name your placeholder by adding a short piece of descriptive text to the % or !, such as %user or %node.')); 518 } 519 520 if ($bit[0] == '%') { 521 if ($found) { 522 form_error($form['path'], t('You cannot have a dynamic path element after an optional path element.')); 523 } 524 525 if ($position == 0) { 526 form_error($form['path'], t('The first element in a path may not be dynamic.')); 527 } 528 529 $path[] = '%'; 530 } 531 else if ($bit[0] == '!') { 532 $found = TRUE; 533 } 534 else { 535 if ($found) { 536 form_error($form['path'], t('You cannot have a static path element after an optional path element.')); 537 } 538 $path[] = $bit; 539 } 540 } 541 542 // Check to see if something that isn't a page manager page is using the path. 543 $path = implode('/', $path); 544 $result = db_query("SELECT * FROM {menu_router} WHERE path = '%s'", $path); 545 while ($router = db_fetch_object($result)) { 546 if ($router->page_callback != 'page_manager_page_execute') { 547 form_error($form['path'], t('That path is already in use. This system cannot override existing paths.')); 548 } 549 } 550 551 // Ensure the path is not already an alias to something else. 552 if (strpos($path, '%') === FALSE) { 553 $result = db_query("SELECT src, dst FROM {url_alias} WHERE dst = '%s'", $path); 554 if ($alias = db_fetch_object($result)) { 555 form_error($form['path'], t('That path is currently assigned to be an alias for @alias. This system cannot override existing aliases.', array('@alias' => $alias->src))); 556 } 557 } 558 else { 559 if (!empty($form_state['values']['frontpage'])) { 560 form_error($form['path'], t('You cannot make this page your site home page if it uses % placeholders.')); 561 } 562 } 563 564 // Ensure path is properly formed. 565 $args = page_manager_page_get_named_arguments($form_state['values']['path']); 566 if ($invalid_args = array_filter($args, 'page_manager_page_form_basic_validate_filter')) { 567 foreach ($invalid_args as $arg => $position) { 568 form_error($form['path'], t('Duplicated argument %arg', array('%arg' => $arg))); 569 } 570 } 571 572 if (isset($args['%'])) { 573 form_error($form['path'], t('Invalid arg <em>%</em>. All arguments must be named with keywords.')); 574 } 575 576 $form_state['arguments'] = $args; 577 } 578 579 /** 580 * Store the values from the basic settings form. 581 */ 582 function page_manager_page_form_basic_submit(&$form, &$form_state) { 583 $page = &$form_state['page']->subtask['subtask']; 584 $cache = &$form_state['page']; 585 586 // If this is a new thing, then we have to do a bunch of setup to create 587 // the cache record with the right ID and some basic data that we could 588 // not know until we asked the user some questions. 589 if (!isset($page->pid) && !empty($form_state['creating'])) { 590 // Update the data with our new name. 591 $page->name = $form_state['values']['name']; 592 $form_state['page']->task_name = page_manager_make_task_name($form_state['task_id'], $page->name); 593 $cache->handler = $form_state['values']['handler']; 594 $cache->subtask_id = $page->name; 595 $plugin = page_manager_get_task_handler($cache->handler); 596 597 // If they created and went back, there might be old, dead handlers 598 // that are not going to be added. 599 // 600 // Remove them: 601 $cache->handlers = array(); 602 $cache->handler_info = array(); 603 604 // Create a new handler. 605 $handler = page_manager_new_task_handler($plugin); 606 $title = !empty($form_state['values']['title']) ? $form_state['values']['title'] : $plugin['title']; 607 page_manager_handler_add_to_page($cache, $handler, $title); 608 609 // Figure out which forms to present them with 610 $cache->forms = array(); 611 $cache->forms[] = 'basic'; // This one is always there. 612 if (!empty($form_state['arguments'])) { 613 $cache->forms[] = 'argument'; 614 } 615 616 $features = $form_state['values']['features']; 617 $cache->forms = array_merge($cache->forms, array_keys(array_filter($features['default']))); 618 if (isset($features[$form_state['values']['handler']])) { 619 $cache->forms = array_merge($cache->forms, array_keys(array_filter($features[$form_state['values']['handler']]))); 620 } 621 622 if (isset($plugin['required forms'])) { 623 $cache->forms = array_merge($cache->forms, array_keys($plugin['required forms'])); 624 } 625 } 626 627 $page->admin_title = $form_state['values']['admin_title']; 628 $cache->subtask['admin title'] = check_plain($form_state['values']['admin_title']); 629 630 $page->admin_description = $form_state['values']['admin_description']; 631 $cache->subtask['admin description'] = filter_xss_admin($form_state['values']['admin_description']); 632 633 if ($page->path != $form_state['values']['path']) { 634 $page->path = $form_state['values']['path']; 635 page_manager_page_recalculate_arguments($page); 636 $cache->path_changed = TRUE; 637 } 638 639 $page->make_frontpage = !empty($form_state['values']['frontpage']); 640 } 641 642 /** 643 * Form to handle menu item controls. 644 */ 645 function page_manager_page_form_menu(&$form, &$form_state) { 646 ctools_include('dependent'); 647 $form['menu'] = array( 648 '#prefix' => '<div class="clear-block">', 649 '#suffix' => '</div>', 650 '#tree' => TRUE, 651 ); 652 653 $menu = $form_state['page']->subtask['subtask']->menu; 654 if (empty($menu)) { 655 $menu = array( 656 'type' => 'none', 657 'title' => '', 658 'weight' => 0, 659 'name' => 'navigation', 660 'parent' => array( 661 'type' => 'none', 662 'title' => '', 663 'weight' => 0, 664 'name' => 'navigation', 665 ), 666 ); 667 } 668 669 $form['menu']['type'] = array( 670 '#title' => t('Type'), 671 '#type' => 'radios', 672 '#options' => array( 673 'none' => t('No menu entry'), 674 'normal' => t('Normal menu entry'), 675 'tab' => t('Menu tab'), 676 'default tab' => t('Default menu tab'), 677 ), 678 '#default_value' => $menu['type'], 679 ); 680 681 $form['menu']['title'] = array( 682 '#title' => t('Title'), 683 '#type' => 'textfield', 684 '#default_value' => $menu['title'], 685 '#description' => t('If set to normal or tab, enter the text to use for the menu item.'), 686 '#process' => array('ctools_dependent_process'), 687 '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), 688 ); 689 690 list($major, $minor) = explode('.', VERSION, 2); 691 692 $form['menu']['name-warning'] = array( 693 '#type' => 'markup', 694 '#prefix' => '<div class="warning">', 695 '#value' => t("Warning: Changing this item's menu will not work reliably in Drupal 6.4 or earlier. Please upgrade your copy of Drupal at !url.", array('!url' => l('drupal.org', 'http://drupal.org/project/Drupal+project'))), 696 '#suffix' => '</div>', 697 '#process' => array('ctools_dependent_process'), 698 '#dependency' => array('radio:menu[type]' => array('normal')), 699 '#access' => ($minor < 5), 700 ); 701 702 // Only display the menu selector if menu module is enabled. 703 if (module_exists('menu')) { 704 $form['menu']['name'] = array( 705 '#title' => t('Menu'), 706 '#type' => 'select', 707 '#options' => menu_get_menus(), 708 '#default_value' => $menu['name'], 709 '#description' => t('Insert item into an available menu.'), 710 '#process' => array('ctools_dependent_process'), 711 '#dependency' => array('radio:menu[type]' => array('normal')), 712 ); 713 } 714 else { 715 $form['menu']['name'] = array( 716 '#type' => 'value', 717 '#value' => $menu['name'], 718 ); 719 $form['menu']['markup'] = array( 720 '#value' => t('Menu selection requires the activation of menu module.'), 721 ); 722 } 723 $form['menu']['weight'] = array( 724 '#title' => t('Weight'), 725 '#type' => 'textfield', 726 '#default_value' => isset($menu['weight']) ? $menu['weight'] : 0, 727 '#description' => t('The lower the weight the higher/further left it will appear.'), 728 '#process' => array('ctools_dependent_process'), 729 '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), 730 ); 731 732 $form['menu']['parent']['type'] = array( 733 '#prefix' => '<div id="edit-menu-parent-type-wrapper">', 734 '#suffix' => '</div>', 735 '#title' => t('Parent menu item'), 736 '#type' => 'radios', 737 '#options' => array('none' => t('Already exists'), 'normal' => t('Normal menu item'), 'tab' => t('Menu tab')), 738 '#default_value' => $menu['parent']['type'], 739 '#description' => t('When providing a menu item as a default tab, Drupal needs to know what the parent menu item of that tab will be. Sometimes the parent will already exist, but other times you will need to have one created. The path of a parent item will always be the same path with the last part left off. i.e, if the path to this view is <em>foo/bar/baz</em>, the parent path would be <em>foo/bar</em>.'), 740 '#process' => array('expand_radios', 'ctools_dependent_process'), 741 '#dependency' => array('radio:menu[type]' => array('default tab')), 742 ); 743 $form['menu']['parent']['title'] = array( 744 '#title' => t('Parent item title'), 745 '#type' => 'textfield', 746 '#default_value' => $menu['parent']['title'], 747 '#description' => t('If creating a parent menu item, enter the title of the item.'), 748 '#process' => array('ctools_dependent_process'), 749 '#dependency' => array('radio:menu[type]' => array('default tab'), 'radio:menu[parent][type]' => array('normal', 'tab')), 750 '#dependency_count' => 2, 751 ); 752 // Only display the menu selector if menu module is enabled. 753 if (module_exists('menu')) { 754 $form['menu']['parent']['name'] = array( 755 '#title' => t('Parent item menu'), 756 '#type' => 'select', 757 '#options' => menu_get_menus(), 758 '#default_value' => $menu['parent']['name'], 759 '#description' => t('Insert item into an available menu.'), 760 '#process' => array('ctools_dependent_process'), 761 '#dependency' => array('radio:menu[type]' => array('default tab'), 'radio:menu[parent][type]' => array('normal')), 762 '#dependency_count' => 2, 763 ); 764 } 765 else { 766 $form['menu']['parent']['name'] = array( 767 '#type' => 'value', 768 '#value' => $menu['parent']['name'], 769 ); 770 } 771 $form['menu']['parent']['weight'] = array( 772 '#title' => t('Tab weight'), 773 '#type' => 'textfield', 774 '#default_value' => $menu['parent']['weight'], 775 '#size' => 5, 776 '#description' => t('If the parent menu item is a tab, enter the weight of the tab. The lower the number, the more to the left it will be.'), 777 '#process' => array('ctools_dependent_process'), 778 '#dependency' => array('radio:menu[type]' => array('default tab'), 'radio:menu[parent][type]' => array('tab')), 779 '#dependency_count' => 2, 780 ); 781 } 782 783 /** 784 * Validate handler for the menu form for add/edit page task. 785 */ 786 function page_manager_page_form_menu_validate(&$form, &$form_state) { 787 // If setting a 'normal' menu entry, make sure that any placeholders 788 // support the to_arg stuff. 789 790 if ($form_state['values']['menu']['type'] == 'normal') { 791 $page = $form_state['page']->subtask['subtask']; 792 793 foreach (explode('/', $page->path) as $bit) { 794 if (!isset($bit) || $bit === '') { 795 continue; 796 } 797 798 if ($bit[0] == '%') { 799 // Chop off that %. 800 $name = substr($bit, 1); 801 802 // Check to see if the argument plugin allows to arg: 803 if (!empty($page->arguments[$name])) { 804 ctools_include('context'); 805 $plugin = ctools_get_argument($page->arguments[$name]['name']); 806 if (!empty($plugin['path placeholder to_arg'])) { 807 continue; 808 } 809 } 810 811 form_error($form['menu']['type'], t('Paths with non optional placeholders cannot be used as normal menu items unless the selected argument handler provides a default argument to use for the menu item.')); 812 return; 813 } 814 } 815 } 816 } 817 818 /** 819 * Submit handler for the menu form for add/edit page task. 820 */ 821 function page_manager_page_form_menu_submit(&$form, &$form_state) { 822 $form_state['page']->subtask['subtask']->menu = $form_state['values']['menu']; 823 $form_state['page']->path_changed = TRUE; 824 } 825 826 /** 827 * Form to handle menu item controls. 828 */ 829 function page_manager_page_form_access(&$form, &$form_state) { 830 ctools_include('context'); 831 $form_state['module'] = 'page_manager_page'; 832 $form_state['callback argument'] = $form_state['page']->task_name; 833 $form_state['access'] = $form_state['page']->subtask['subtask']->access; 834 $form_state['no buttons'] = TRUE; 835 $form_state['contexts'] = array(); 836 837 // Load contexts based on argument data: 838 if ($arguments = _page_manager_page_get_arguments($form_state['page']->subtask['subtask'])) { 839 $form_state['contexts'] = ctools_context_get_placeholders_from_argument($arguments); 840 } 841 842 ctools_include('context-access-admin'); 843 $form = array_merge($form, ctools_access_admin_form($form_state)); 844 } 845 846 /** 847 * Submit handler to deal with access control changes. 848 */ 849 function page_manager_page_form_access_submit(&$form, &$form_state) { 850 $form_state['page']->subtask['subtask']->access['logic'] = $form_state['values']['logic']; 851 $form_state['page']->path_changed = TRUE; 852 } 853 854 /** 855 * Form to handle assigning argument handlers to named arguments. 856 */ 857 function page_manager_page_form_argument(&$form, &$form_state) { 858 $page = &$form_state['page']->subtask['subtask']; 859 $path = $page->path; 860 861 $arguments = page_manager_page_get_named_arguments($path); 862 863 $form['table'] = array( 864 '#theme' => 'page_manager_page_form_argument_table', 865 '#page-manager-path' => $path, 866 'argument' => array(), 867 ); 868 869 $task_name = $form_state['page']->task_name; 870 foreach ($arguments as $keyword => $position) { 871 $conf = array(); 872 873 if (isset($page->temporary_arguments[$keyword]) && !empty($form_state['allow temp'])) { 874 $conf = $page->temporary_arguments[$keyword]; 875 } 876 else if (isset($page->arguments[$keyword])) { 877 $conf = $page->arguments[$keyword]; 878 } 879 880 $context = t('No context assigned'); 881 882 $plugin = array(); 883 if ($conf && isset($conf['name'])) { 884 ctools_include('context'); 885 $plugin = ctools_get_argument($conf['name']); 886 887 if (isset($plugin['title'])) { 888 $context = $plugin['title']; 889 } 890 } 891 892 $form['table']['argument'][$keyword]['#keyword'] = $keyword; 893 $form['table']['argument'][$keyword]['#position'] = $position; 894 $form['table']['argument'][$keyword]['#context'] = $context; 895 896 // The URL for this ajax button 897 $form['table']['argument'][$keyword]['change-url'] = array( 898 '#attributes' => array('class' => "page-manager-context-$keyword-change-url"), 899 '#type' => 'hidden', 900 '#value' => url("admin/build/pages/argument/change/$task_name/$keyword", array('absolute' => TRUE)), 901 ); 902 $form['table']['argument'][$keyword]['change'] = array( 903 '#type' => 'submit', 904 '#value' => t('Change'), 905 '#attributes' => array('class' => 'ctools-use-modal'), 906 '#id' => "page-manager-context-$keyword-change", 907 ); 908 909 $form['table']['argument'][$keyword]['settings'] = array(); 910 911 // Only show the button if this has a settings form available: 912 if (!empty($plugin)) { 913 // The URL for this ajax button 914 $form['table']['argument'][$keyword]['settings-url'] = array( 915 '#attributes' => array('class' => "page-manager-context-$keyword-settings-url"), 916 '#type' => 'hidden', 917 '#value' => url("admin/build/pages/argument/settings/$task_name/$keyword", array('absolute' => TRUE)), 918 ); 919 $form['table']['argument'][$keyword]['settings'] = array( 920 '#type' => 'submit', 921 '#value' => t('Settings'), 922 '#attributes' => array('class' => 'ctools-use-modal'), 923 '#id' => "page-manager-context-$keyword-settings", 924 ); 925 } 926 } 927 } 928 929 /** 930 * Theme the table for this form. 931 */ 932 function theme_page_manager_page_form_argument_table($form) { 933 $header = array( 934 array('data' => t('Argument'), 'class' => 'page-manager-argument'), 935 array('data' => t('Position in path'), 'class' => 'page-manager-position'), 936 array('data' => t('Context assigned'), 'class' => 'page-manager-context'), 937 array('data' => t('Operations'), 'class' => 'page-manager-operations'), 938 ); 939 940 $rows = array(); 941 942 ctools_include('modal'); 943 ctools_modal_add_js(); 944 foreach (element_children($form['argument']) as $key) { 945 $row = array(); 946 $row[] = '%' . check_plain($form['argument'][$key]['#keyword']); 947 $row[] = check_plain($form['argument'][$key]['#position']); 948 $row[] = $form['argument'][$key]['#context'] . ' ' . drupal_render($form['argument'][$key]['change']);; 949 $row[] = drupal_render($form['argument'][$key]['settings']) . drupal_render($form['argument'][$key]); 950 951 $rows[] = array('data' => $row); 952 } 953 954 if (!$rows) { 955 $rows[] = array(array('data' => t('The path %path has no arguments to configure.', array('%path' => $form['#page-manager-path'])), 'colspan' => 4)); 956 } 957 958 $attributes = array( 959 'id' => 'page-manager-argument-table', 960 ); 961 962 $output = theme('table', $header, $rows, $attributes); 963 return $output; 964 } 965 966 /** 967 * Ajax entry point to edit an item 968 */ 969 function page_manager_page_subtask_argument_ajax($step = NULL, $task_name = NULL, $keyword = NULL) { 970 ctools_include('ajax'); 971 ctools_include('modal'); 972 ctools_include('context'); 973 ctools_include('wizard'); 974 975 if (!$step) { 976 return ctools_ajax_render_error(); 977 } 978 979 if (!$cache = page_manager_get_page_cache($task_name)) { 980 return ctools_ajax_render_error(t('Invalid object name.')); 981 } 982 983 $page = &$cache->subtask['subtask']; 984 $path = $page->path; 985 $arguments = page_manager_page_get_named_arguments($path); 986 987 // Load stored object from cache. 988 if (!isset($arguments[$keyword])) { 989 return ctools_ajax_render_error(t('Invalid keyword.')); 990 } 991 992 // Set up wizard info 993 $form_info = array( 994 'id' => 'page_manager_page_argument', 995 'path' => "admin/build/pages/argument/%step/$task_name/$keyword", 996 'show cancel' => TRUE, 997 'next callback' => 'page_manager_page_argument_next', 998 'finish callback' => 'page_manager_page_argument_finish', 999 'cancel callback' => 'page_manager_page_argument_cancel', 1000 'order' => array( 1001 'change' => t('Change context type'), 1002 'settings' => t('Argument settings'), 1003 ), 1004 'forms' => array( 1005 'change' => array( 1006 'title' => t('Change argument'), 1007 'form id' => 'page_manager_page_argument_form_change', 1008 ), 1009 'settings' => array( 1010 'title' => t('Argument settings'), 1011 'form id' => 'page_manager_page_argument_form_settings', 1012 ), 1013 ), 1014 ); 1015 1016 $form_state = array( 1017 'page' => $cache, 1018 'keyword' => $keyword, 1019 'ajax' => TRUE, 1020 'modal' => TRUE, 1021 'commands' => array(), 1022 ); 1023 1024 // With 'modal' and 'ajax' true, rendering automatically happens here so 1025 // we do nothing with the result. 1026 $output = ctools_wizard_multistep_form($form_info, $step, $form_state); 1027 } 1028 1029 /** 1030 * Callback generated when the add page process is finished. 1031 */ 1032 function page_manager_page_argument_finish(&$form_state) { 1033 // Check to see if there are changes. 1034 $page = &$form_state['page']->subtask['subtask']; 1035 $keyword = &$form_state['keyword']; 1036 1037 if (isset($page->temporary_arguments[$keyword])) { 1038 $page->arguments[$keyword] = $page->temporary_arguments[$keyword]; 1039 } 1040 1041 if (isset($page->temporary_arguments)) { 1042 unset($page->temporary_arguments); 1043 } 1044 1045 // Update the cache with changes. 1046 page_manager_set_page_cache($form_state['page']); 1047 1048 // Rerender the table so we can ajax it back in. 1049 // Go directly to the form and retrieve it using a blank form and 1050 // a clone of our current form state. This is an abbreviated 1051 // drupal_get_form that is halted prior to render and is never 1052 // fully processed, but is guaranteed to produce the same form we 1053 // started with so we don't have to do crazy stuff to rerender 1054 // just part of it. 1055 1056 // @todo should there be a tool to do this? 1057 1058 $clone_state = $form_state; 1059 $clone_state['allow temp'] = TRUE; 1060 $form = array(); 1061 page_manager_page_form_argument($form, $clone_state); 1062 drupal_prepare_form('page_manager_page_form_argument', $form, $clone_state); 1063 $form['#post'] = array(); 1064 $form = form_builder('page_manager_page_form_argument', $form, $clone_state); 1065 1066 // Render just the table portion. 1067 $output = drupal_render($form['table']); 1068 $form_state['commands'][] = ctools_ajax_command_replace('#page-manager-argument-table', $output); 1069 } 1070 1071 /** 1072 * Callback generated when the 'next' button is clicked. 1073 * 1074 * All we do here is store the cache. 1075 */ 1076 function page_manager_page_argument_next(&$form_state) { 1077 // Update the cache with changes. 1078 page_manager_set_page_cache($form_state['page']); 1079 } 1080 1081 /** 1082 * Callback generated when the 'cancel' button is clicked. 1083 * 1084 * We might have some temporary data lying around. We must remove it. 1085 */ 1086 function page_manager_page_argument_cancel(&$form_state) { 1087 $page = &$form_state['page']->subtask['subtask']; 1088 if (isset($page->temporary_arguments)) { 1089 unset($page->temporary_arguments); 1090 // Update the cache with changes. 1091 page_manager_set_page_cache($page); 1092 } 1093 } 1094 1095 /** 1096 * Basic settings form for a page manager page. 1097 */ 1098 function page_manager_page_argument_form_change(&$form, &$form_state) { 1099 $page = &$form_state['page']->subtask['subtask']; 1100 $keyword = &$form_state['keyword']; 1101 1102 ctools_include('context'); 1103 $plugins = ctools_get_arguments(); 1104 1105 $options = array(); 1106 foreach ($plugins as $id => $plugin) { 1107 $options[$id] = $plugin['title']; 1108 } 1109 1110 asort($options); 1111 1112 $options = array('' => t('No context selected')) + $options; 1113 1114 $argument = ''; 1115 if (isset($page->arguments[$keyword]) && isset($page->arguments[$keyword]['name'])) { 1116 $argument = $page->arguments[$keyword]['name']; 1117 } 1118 1119 $form['argument'] = array( 1120 '#type' => 'radios', 1121 '#options' => $options, 1122 '#default_value' => $argument, 1123 ); 1124 } 1125 1126 /** 1127 * Submit handler to change an argument. 1128 */ 1129 function page_manager_page_argument_form_change_submit(&$form, &$form_state) { 1130 $page = &$form_state['page']->subtask['subtask']; 1131 $keyword = &$form_state['keyword']; 1132 $argument = $form_state['values']['argument']; 1133 1134 // If the argument is not changing, we do not need to do anything. 1135 if (isset($page->arguments[$keyword]['name']) && $page->arguments[$keyword]['name'] == $argument) { 1136 // Set the task to cancel since no change means do nothing: 1137 $form_state['clicked_button']['#wizard type'] = 'cancel'; 1138 return; 1139 } 1140 1141 ctools_include('context'); 1142 1143 // If switching to the no context, just wipe out the old data. 1144 if (empty($argument)) { 1145 $form_state['clicked_button']['#wizard type'] = 'finish'; 1146 $page->temporary_arguments[$keyword] = array( 1147 'settings' => array(), 1148 'identifier' => t('No context'), 1149 ); 1150 return; 1151 } 1152 1153 $plugin = ctools_get_argument($argument); 1154 1155 // Acquire defaults. 1156 $settings = array(); 1157 1158 if (isset($plugin['default'])) { 1159 if (is_array($plugin['default'])) { 1160 $settings = $plugin['default']; 1161 } 1162 else if (function_exists($plugin['default'])) { 1163 $settings = $plugin['default'](); 1164 } 1165 } 1166 1167 $id = ctools_context_next_id($page->arguments, $argument); 1168 $title = isset($plugin['title']) ? $plugin['title'] : t('No context'); 1169 1170 // Set the new argument in a temporary location. 1171 $page->temporary_arguments[$keyword] = array( 1172 'id' => $id, 1173 'identifier' => $title . ($id > 1 ? ' ' . $id : ''), 1174 'name' => $argument, 1175 'settings' => $settings, 1176 ); 1177 } 1178 1179 /** 1180 * Basic settings form for a page manager page. 1181 */ 1182 function page_manager_page_argument_form_settings(&$form, &$form_state) { 1183 $page = &$form_state['page']->subtask['subtask']; 1184 $keyword = &$form_state['keyword']; 1185 1186 if (isset($page->temporary_arguments[$keyword])) { 1187 $conf = $page->temporary_arguments[$keyword]; 1188 } 1189 else if (isset($page->arguments[$keyword])) { 1190 $conf = $page->temporary_arguments[$keyword] = $page->arguments[$keyword]; 1191 } 1192 1193 if (!isset($conf)) { 1194 // This should be impossible and thus never seen. 1195 $form['error'] = array('#value' => t('Error: missing argument.')); 1196 return; 1197 } 1198 1199 ctools_include('context'); 1200 $plugin = ctools_get_argument($conf['name']); 1201 1202 $form['settings'] = array( 1203 '#tree' => TRUE, 1204 ); 1205 1206 $form['identifier'] = array( 1207 '#type' => 'textfield', 1208 '#title' => t('Context identifier'), 1209 '#description' => t('This is the title of the context used to identify it later in the administrative process. This will never be shown to a user.'), 1210 '#default_value' => $conf['identifier'], 1211 ); 1212 1213 if (!$plugin) { 1214 // This should be impossible and thus never seen. 1215 $form['error'] = array('#value' => t('Error: missing or invalid argument plugin %argument.', array('%argument', $argument))); 1216 return; 1217 } 1218 1219 if ($function = ctools_plugin_get_function($plugin, 'settings form')) { 1220 $function($form, $form_state, $conf['settings']); 1221 } 1222 1223 $form_state['plugin'] = $plugin; 1224 } 1225 1226 /** 1227 * Validate handler for argument settings. 1228 */ 1229 function page_manager_page_argument_form_settings_validate(&$form, &$form_state) { 1230 if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form validate')) { 1231 $function($form, $form_state); 1232 } 1233 } 1234 1235 /** 1236 * Submit handler for argument settings. 1237 */ 1238 function page_manager_page_argument_form_settings_submit(&$form, &$form_state) { 1239 if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form submit')) { 1240 $function($form, $form_state); 1241 } 1242 1243 $page = &$form_state['page']->subtask['subtask']; 1244 $keyword = &$form_state['keyword']; 1245 // Copy the form to our temporary location which will get moved again when 1246 // finished. Yes, finished is always next but finish can happen from other 1247 // locations so we funnel through that path rather than duplicate. 1248 $page->temporary_arguments[$keyword]['identifier'] = $form_state['values']['identifier']; 1249 if (isset($form_state['values']['settings'])) { 1250 $page->temporary_arguments[$keyword]['settings'] = $form_state['values']['settings']; 1251 } 1252 else { 1253 $page->temporary_arguments[$keyword]['settings'] = array(); 1254 } 1255 } 1256 1257 /** 1258 * Import a task handler from cut & paste 1259 */ 1260 function page_manager_page_import_subtask(&$form_state, $task_name) { 1261 $form_state['task'] = page_manager_get_task($task_name); 1262 1263 drupal_set_title(t('Import page')); 1264 $form['name'] = array( 1265 '#type' => 'textfield', 1266 '#title' => t('Page name'), 1267 '#description' => t('Enter the name to use for this page if it is different from the source page. Leave blank to use the original name of the page.'), 1268 ); 1269 1270 $form['path'] = array( 1271 '#type' => 'textfield', 1272 '#title' => t('Path'), 1273 '#description' => t('Enter the path to use for this page if it is different from the source page. Leave blank to use the original path of the page.'), 1274 ); 1275 1276 $form['overwrite'] = array( 1277 '#type' => 'checkbox', 1278 '#title' => t('Allow overwrite of an existing page'), 1279 '#description' => t('If the name you selected already exists in the database, this page will be allowed to overwrite the existing page.'), 1280 ); 1281 1282 $form['object'] = array( 1283 '#type' => 'textarea', 1284 '#title' => t('Paste page code here'), 1285 '#rows' => 15, 1286 ); 1287 1288 $form['submit'] = array( 1289 '#type' => 'submit', 1290 '#value' => t('Import'), 1291 ); 1292 return $form; 1293 } 1294 1295 /** 1296 * Ensure we got a valid page. 1297 */ 1298 function page_manager_page_import_subtask_validate(&$form, &$form_state) { 1299 ob_start(); 1300 eval($form_state['values']['object']); 1301 ob_end_clean(); 1302 1303 if (!isset($page) || !is_object($page)) { 1304 $errors = ob_get_contents(); 1305 if (empty($errors)) { 1306 $errors = t('No handler found.'); 1307 } 1308 form_error($form['object'], t('Unable to get a page from the import. Errors reported: @errors', array('@errors' => $errors))); 1309 } 1310 1311 if (empty($form_state['values']['name'])) { 1312 $form_state['values']['name'] = $page->name; 1313 } 1314 1315 $task_name = page_manager_make_task_name('page', $form_state['values']['name']); 1316 $form_state['cache'] = page_manager_get_page_cache($task_name); 1317 1318 if ($form_state['cache'] && $form_state['cache']->locked) { 1319 form_error($form['name'], t('That page name is in use and locked by another user. You must <a href="!break">break the lock</a> on that page before proceeding, or choose a different name.', array('!break' => url(page_manager_edit_url($task_name, array('actions', 'break-lock')))))); 1320 return; 1321 } 1322 1323 if (empty($form_state['values']['path'])) { 1324 $form_state['values']['path'] = $page->path; 1325 } 1326 1327 if (empty($form_state['values']['overwrite'])) { 1328 $page->name = NULL; 1329 } 1330 1331 $form_state['page'] = new stdClass(); 1332 $form_state['page']->subtask['subtask'] = $page; 1333 page_manager_page_form_basic_validate($form, $form_state); 1334 } 1335 1336 /** 1337 * Submit the import page to create the new page and redirect. 1338 */ 1339 function page_manager_page_import_subtask_submit($form, &$form_state) { 1340 $page = &$form_state['page']->subtask['subtask']; 1341 $page->name = $form_state['values']['name']; 1342 $page->path = $form_state['values']['path']; 1343 1344 $task_name = page_manager_make_task_name('page', $page->name); 1345 $cache = page_manager_get_page_cache($task_name); 1346 if (!$cache) { 1347 $cache = new stdClass(); 1348 } 1349 1350 page_manager_page_new_page_cache($page, $cache); 1351 page_manager_set_page_cache($cache); 1352 1353 $form_state['redirect'] = page_manager_edit_url($task_name); 1354 } 1355 1356 /** 1357 * Entry point to export a page. 1358 */ 1359 function page_manager_page_form_export(&$form, &$form_state) { 1360 $page = $form_state['page']->subtask['subtask']; 1361 1362 $export = page_manager_page_export($page, $form_state['page']->handlers); 1363 1364 $lines = substr_count($export, "\n"); 1365 $form['code'] = array( 1366 '#type' => 'textarea', 1367 '#default_value' => $export, 1368 '#rows' => $lines, 1369 ); 1370 1371 unset($form['buttons']); 1372 } 1373 1374 /** 1375 * Entry point to clone a page. 1376 */ 1377 function page_manager_page_form_clone(&$form, &$form_state) { 1378 $page = &$form_state['page']->subtask['subtask']; 1379 1380 // This provides its own button because it does something totally different. 1381 unset($form['buttons']); 1382 $form['name'] = array( 1383 '#type' => 'textfield', 1384 '#title' => t('Page name'), 1385 '#description' => t('Enter the name to the new page It must be unique and contain only alphanumeric characters and underscores.'), 1386 ); 1387 1388 $form['admin_title'] = array( 1389 '#type' => 'textfield', 1390 '#title' => t('Administrative title'), 1391 '#description' => t('The name of this page. This will appear in the administrative interface to easily identify it.'), 1392 '#default_value' => $page->admin_title, 1393 ); 1394 1395 // path 1396 $form['path'] = array( 1397 '#type' => 'textfield', 1398 '#title' => t('Path'), 1399 '#description' => t('The URL path to get to this page. You may create named placeholders for variable parts of the path by using %name for required elements and !name for optional elements. For example: "node/%node/foo", "forum/%forum" or "dashboard/!input". These named placeholders can be turned into contexts on the arguments form. You cannot use the same path as the original page.'), 1400 '#default_value' => $page->path, 1401 ); 1402 1403 $form['handlers'] = array( 1404 '#type' => 'checkbox', 1405 '#title' => t('Clone variants'), 1406 '#description' => t('If checked all variants associated with the page will be cloned as well. If not checked the page will be cloned without variants.'), 1407 '#default_value' => TRUE, 1408 ); 1409 1410 $form['submit'] = array( 1411 '#type' => 'submit', 1412 '#value' => t('Clone'), 1413 ); 1414 } 1415 1416 /** 1417 * Validate clone page form. 1418 */ 1419 function page_manager_page_form_clone_validate(&$form, &$form_state) { 1420 $page = &$form_state['page']->subtask['subtask']; 1421 1422 $page->old_name = $page->name; 1423 $page->name = NULL; 1424 page_manager_page_form_basic_validate($form, $form_state); 1425 } 1426 1427 /** 1428 * submit clone page form. 1429 * 1430 * Load the page, change the name(s) to protect the innocent, and if 1431 * requested, load all the task handlers so that they get saved properly too. 1432 */ 1433 function page_manager_page_form_clone_submit(&$form, &$form_state) { 1434 $original = $form_state['page']->subtask['subtask']; 1435 1436 $original->name = $form_state['values']['name']; 1437 $original->admin_title = $form_state['values']['admin_title']; 1438 $original->path = $form_state['values']['path']; 1439 1440 $handlers = !empty($form_state['values']['handlers']) ? $form_state['page']->handlers : FALSE; 1441 // Export the handler, which is a fantastic way to clean database IDs out of it. 1442 $export = page_manager_page_export($original, $handlers); 1443 ob_start(); 1444 eval($export); 1445 ob_end_clean(); 1446 1447 $task_name = page_manager_make_task_name('page', $page->name); 1448 $cache = new stdClass(); 1449 1450 page_manager_page_new_page_cache($page, $cache); 1451 page_manager_set_page_cache($cache); 1452 1453 $form_state['redirect'] = page_manager_edit_url($task_name); 1454 } 1455 1456 /** 1457 * Entry point to export a page. 1458 */ 1459 function page_manager_page_form_delete(&$form, &$form_state) { 1460 $page = &$form_state['page']->subtask['subtask']; 1461 1462 if ($page->type == t('Overridden')) { 1463 $text = t('Reverting the page will delete the page that is in the database, reverting it to the original default page. Any changes you have made will be lost and cannot be recovered.'); 1464 } 1465 else { 1466 $text = t('Are you sure you want to delete this page? Deleting a page cannot be undone.'); 1467 } 1468 $form['markup'] = array( 1469 '#value' => '<p>' . $text . '</p>', 1470 ); 1471 1472 if (empty($form_state['page']->locked)) { 1473 unset($form['buttons']); 1474 $form['delete'] = array( 1475 '#type' => 'submit', 1476 '#value' => $page->type == t('Overridden') ? t('Revert') : t('Delete'), 1477 ); 1478 } 1479 } 1480 1481 /** 1482 * Submit handler to delete a view. 1483 */ 1484 function page_manager_page_form_delete_submit(&$form, &$form_state) { 1485 $page = $form_state['page']->subtask['subtask']; 1486 page_manager_page_delete($page); 1487 if ($page->type != t('Overridden')) { 1488 $form_state['redirect'] = 'admin/build/pages'; 1489 drupal_set_message(t('The page has been deleted.')); 1490 } 1491 else { 1492 $form_state['redirect'] = page_manager_edit_url($form_state['page']->task_name, array('summary')); 1493 drupal_set_message(t('The page has been reverted.')); 1494 } 1495 }
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 |