5 * Administrative functions for the page manager.
7 * This provides the UI to list, create, edit and delete pages, though much
8 * of this is delegated through to individual tasks.
12 * Output a list of pages that are managed.
14 function page_manager_list_page($js = NULL) {
15 // Prevent this page from showing up when random other links fail.
16 if ($js && $js != 'ajax' && $js != 'nojs') {
17 return MENU_NOT_FOUND;
20 // TRUE if 'ajax', FALSE if otherwise.
23 // If we do any form rendering, it's to completely replace a form on the
24 // page, so don't let it force our ids to change.
25 if ($js && isset($_POST['ajax_html_ids'])) {
26 unset($_POST['ajax_html_ids']);
29 if (module_exists('advanced_help') && !$js) {
30 drupal_set_message(theme('advanced_help_topic', array(
31 'module' => 'page_manager',
32 'topic' => 'getting-started',
33 'type' => t('See the getting started guide for more information.'),
37 $tasks = page_manager_get_tasks_by_type('page');
38 $pages = array('operations' => array(), 'tasks' => array());
40 page_manager_get_pages($tasks, $pages);
42 // Add lock icon to all locked tasks.
45 ctools_include('object-cache');
46 $locks = ctools_object_cache_test_objects('page_manager_page', $pages['tasks']);
47 foreach ($locks as $task_name => $lock) {
48 if ($lock->uid == $user->uid) {
49 $pages['rows'][$task_name]['class'][] = ' page-manager-locked';
50 $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by you. Nobody else may edit this page until these changes are saved or canceled.');
53 $pages['rows'][$task_name]['class'][] = ' page-manager-locked-other';
54 $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by another user. You may not edit this page without breaking the lock.');
60 // Respond to a reset command by clearing session and doing a drupal goto
61 // back to the base URL.
62 if (isset($input['op']) && $input['op'] == t('Reset')) {
63 unset($_SESSION['page_manager']['#admin']);
65 drupal_goto($_GET['q']);
67 // clear everything but form id, form build id and form token:
68 $keys = array_keys($input);
69 foreach ($keys as $id) {
70 if ($id != 'form_id' && $id != 'form_build_id' && $id != 'form_token') {
76 if (count($input) <= 1) {
77 if (isset($_SESSION['page_manager']['#admin']) && is_array($_SESSION['page_manager']['#admin'])) {
78 $input = $_SESSION['page_manager']['#admin'];
82 $_SESSION['page_manager']['#admin'] = $input;
83 unset($_SESSION['page_manager']['#admin']['q']);
90 'no_redirect' => TRUE,
93 // This form will sort and filter the pages.
94 $form = drupal_build_form('page_manager_list_pages_form', $form_state);
97 array('data' => t('Type'), 'class' => array('page-manager-page-type')),
98 array('data' => t('Module'), 'class' => array('page-manager-page-module')),
99 array('data' => t('Name'), 'class' => array('page-manager-page-name')),
100 array('data' => t('Title'), 'class' => array('page-manager-page-title')),
101 array('data' => t('Path'), 'class' => array('page-manager-page-path')),
102 array('data' => t('Storage'), 'class' => array('page-manager-page-storage')),
105 $header[] = array('data' => t('Operations'), 'class' => array('page-manager-page-operations'));
106 $table = theme('table', array('header' => $header, 'rows' => $pages['rows'], 'attributes' => array('id' => 'page-manager-list-pages')));
108 $operations = '<div id="page-manager-links" class="links">' . theme('links', array('links' => $pages['operations'])) . '</div>';
110 drupal_add_css(drupal_get_path('module', 'page_manager') . '/css/page-manager.css');
114 return array('#markup' => drupal_render($form) . $table . $operations);
117 ctools_include('ajax');
119 $commands[] = ajax_command_replace('#page-manager-list-pages', $table);
120 if (!empty($replace_form)) {
121 $commands[] = ajax_command_replace('#page-manager-list-pages-form', drupal_render($form));
123 print ajax_render($commands);
128 * Sort tasks into buckets based upon whether or not they have subtasks.
130 function page_manager_get_pages($tasks, &$pages, $task_id = NULL) {
131 foreach ($tasks as $id => $task) {
132 if (empty($task_id) && !empty($task['page operations'])) {
133 $pages['operations'] = array_merge($pages['operations'], $task['page operations']);
136 // If a type has subtasks, add its subtasks in its own table.
137 if (!empty($task['subtasks'])) {
138 page_manager_get_pages(page_manager_get_task_subtasks($task), $pages, $task['name']);
142 if (isset($task_id)) {
143 $task_name = page_manager_make_task_name($task_id, $task['name']);
146 $task_name = $task['name'];
149 $class = array('page-task-' . $id);
150 if (isset($task['row class'])) {
151 $class[] = $task['row class'];
154 if (!empty($task['disabled'])) {
155 $class[] = 'page-manager-disabled';
160 if (!empty($task['admin path'])) {
161 foreach (explode('/', $task['admin path']) as $bit) {
162 if (isset($bit[0]) && $bit[0] != '!') {
167 $path = implode('/', $path);
168 if (empty($task['disabled']) && strpos($path, '%') === FALSE) {
169 $visible_path = l('/' . $task['admin path'], $path);
172 $visible_path = '/' . $task['admin path'];
176 $row = array('data' => array(), 'class' => $class, 'title' => strip_tags($task['admin description']));
178 $type = isset($task['admin type']) ? $task['admin type'] : t('System');
179 if (isset($task['module'])) {
180 $module = $task['module'];
182 elseif (isset($task['subtask']->export_module)) {
183 $module = $task['subtask']->export_module;
188 $pages['types'][$type] = $type;
189 $row['data']['type'] = array('data' => $type, 'class' => array('page-manager-page-type'));
190 $row['data']['module'] = array('data' => $module, 'class' => array('page-manager-page-module'));
191 $row['data']['name'] = array('data' => $task_name, 'class' => array('page-manager-page-name'));
192 $row['data']['title'] = array('data' => $task['admin title'], 'class' => array('page-manager-page-title'));
193 $row['data']['path'] = array('data' => $visible_path, 'class' => array('page-manager-page-path'));
195 $storage = isset($task['storage']) ? $task['storage'] : t('In code');
196 $pages['storages'][$storage] = $storage;
197 $row['data']['storage'] = array('data' => $storage, 'class' => array('page-manager-page-storage'));
201 if (empty($task['disabled'])) {
202 $item = menu_get_item($path);
213 'title' => t('Edit'),
214 'href' => page_manager_edit_url($task_name),
218 if (!empty($task['enable callback'])) {
219 if (!empty($task['disabled'])) {
220 array_unshift($operations, array(
221 'title' => t('Enable'),
222 'href' => 'admin/structure/pages/nojs/enable/' . $task_name,
223 'query' => array('token' => drupal_get_token($task_name)),
227 $operations[] = array(
228 'title' => t('Disable'),
229 'href' => 'admin/structure/pages/nojs/disable/' . $task_name,
230 'query' => array('token' => drupal_get_token($task_name)),
235 $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
237 $row['data']['operations'] = array('data' => $ops, 'class' => array('page-manager-page-operations'));
239 $pages['disabled'][$task_name] = !empty($task['disabled']);
240 $pages['tasks'][] = $task_name;
241 $pages['rows'][$task_name] = $row;
246 * Provide a form for sorting and filtering the list of pages.
248 function page_manager_list_pages_form($form, &$form_state) {
249 // This forces the form to *always* treat as submitted which is
250 // necessary to make it work.
252 $form["#programmed"] = TRUE;
254 $form['#action'] = url('admin/structure/pages/nojs/', array('absolute' => TRUE));
255 if (!variable_get('clean_url', FALSE)) {
258 '#value' => $_GET['q'],
262 $all = array('all' => t('<All>'));
264 $form['type'] = array(
266 '#title' => t('Type'),
267 '#options' => $all + $form_state['pages']['types'],
268 '#default_value' => 'all',
271 $form['storage'] = array(
273 '#title' => t('Storage'),
274 '#options' => $all + $form_state['pages']['storages'],
275 '#default_value' => 'all',
278 $form['disabled'] = array(
280 '#title' => t('Enabled'),
281 '#options' => $all + array('0' => t('Enabled'), '1' => t('Disabled')),
282 '#default_value' => 'all',
285 $form['search'] = array(
286 '#type' => 'textfield',
287 '#title' => t('Search'),
290 $form['order'] = array(
292 '#title' => t('Sort by'),
294 'disabled' => t('Enabled, title'),
295 'title' => t('Title'),
299 'storage' => t('Storage'),
301 '#default_value' => 'disabled',
304 $form['sort'] = array(
306 '#title' => t('Order'),
311 '#default_value' => 'asc',
314 $form['submit'] = array(
315 '#name' => '', // so it won't in the $_GET args
317 '#id' => 'edit-pages-apply',
318 '#value' => t('Apply'),
319 '#attributes' => array('class' => array('use-ajax-submit ctools-auto-submit-click')),
322 $form['reset'] = array(
324 '#id' => 'edit-pages-reset',
325 '#value' => t('Reset'),
326 '#attributes' => array('class' => array('use-ajax-submit')),
329 $form['#attached']['js'] = array(ctools_attach_js('auto-submit'), ctools_attach_js('page-list', 'page_manager'));
330 $form['#attached']['library'][] = array('system', 'drupal.ajax');
331 $form['#attached']['library'][] = array('system', 'jquery.form');
332 $form['#prefix'] = '<div class="clearfix">';
333 $form['#suffix'] = '</div>';
334 $form['#attributes'] = array('class' => array('ctools-auto-submit-full-form'));
340 * Accept submission from the page manager sort/filter form and apply it
341 * to the list of pages.
343 function page_manager_list_pages_form_submit(&$form, &$form_state) {
344 // Filter and re-sort the pages.
347 $rows = $form_state['pages']['rows'];
350 foreach ($rows as $name => $data) {
352 if ($form_state['values']['type'] != 'all' && $form_state['values']['type'] != $data['data']['type']['data']) {
356 if ($form_state['values']['storage'] != 'all' && $form_state['values']['storage'] != $data['data']['storage']['data']) {
360 if ($form_state['values']['disabled'] != 'all' && $form_state['values']['disabled'] != $form_state['pages']['disabled'][$name]) {
364 if ($form_state['values']['search'] &&
365 strpos($data['data']['name']['data'], $form_state['values']['search']) === FALSE &&
366 strpos($data['data']['path']['data'], $form_state['values']['search']) === FALSE &&
367 strpos($data['data']['title']['data'], $form_state['values']['search']) === FALSE) {
371 switch ($form_state['values']['order']) {
373 $sorts[$name] = !$form_state['pages']['disabled'][$name] . $data['data']['title']['data'];
376 $sorts[$name] = $data['data']['title']['data'];
379 $sorts[$name] = $data['data']['name']['data'];
382 $sorts[$name] = $data['data']['path']['data'];
385 $sorts[$name] = $data['data']['type']['data'];
388 $sorts[$name] = $data['data']['storage']['data'];
394 if ($form_state['values']['sort'] == 'desc') {
401 // Nuke the original.
402 $form_state['pages']['rows'] = array();
404 foreach ($sorts as $name => $title) {
405 $form_state['pages']['rows'][$name] = $rows[$name];
411 * Render the edit page for a a page, custom or system.
413 function page_manager_edit_page($page) {
414 drupal_set_title($page->subtask['admin title'], PASS_THROUGH);
415 // Provide and process the save page form before anything else.
416 $form_state = array('page' => &$page);
417 $built_form = drupal_build_form('page_manager_save_page_form', $form_state);
418 $form = drupal_render($built_form);
420 $operations = page_manager_get_operations($page);
421 $args = array('summary');
422 $rendered_operations = page_manager_render_operations($page, $operations, $args, array('class' => array('operations-main')), 'nav');
423 $content = page_manager_get_operation_content(FALSE, $page, $args, $operations);
424 $output = theme('page_manager_edit_page', array('page' => $page, 'save' => $form, 'operations' => $rendered_operations, 'content' => $content));
425 return array('#markup' => $output);
429 * Entry point to edit a single operation for a page.
432 * Whether or not the page was called via javascript.
434 * The cached page that is being edited.
436 * A number of items used to drill down into the actual operation called.
438 function page_manager_edit_page_operation() {
439 $args = func_get_args();
440 $js = array_shift($args);
441 $page = array_shift($args);
443 $operations = page_manager_get_operations($page);
444 $content = page_manager_get_operation_content($js, $page, $args, $operations);
446 // If the operation requested we go somewhere else afterward, oblige it.
447 if (isset($content['new trail'])) {
448 $args = $content['new trail'];
449 // Get operations again, for the operation may have changed their availability.
450 $operations = page_manager_get_operations($page);
451 $content = page_manager_get_operation_content($js, $page, $args, $operations);
454 // Rendering the content may have been a form submission that changed the
455 // operations, such as renaming or adding a handler. Thus we get a new set
457 $operations = page_manager_get_operations($page);
458 $rendered_operations = page_manager_render_operations($page, $operations, $args, array('class' => array('operations-main')), 'nav');
460 // Since this form should never be submitted to this page, process it late so
461 // that we can be sure it notices changes.
462 $form_state = array('page' => &$page);
463 $built_form = drupal_build_form('page_manager_save_page_form', $form_state);
464 $form = drupal_render($built_form);
466 $output = theme('page_manager_edit_page', array('page' => $page, 'save' => $form, 'operations' => $rendered_operations, 'content' => $content));
470 $commands[] = ajax_command_replace('#page-manager-edit', $output);
472 print ajax_render($commands);
477 drupal_set_title($page->subtask['admin title'], PASS_THROUGH);
482 * Take the operations array from a task and expand it.
484 * This allows some of the operations to be dynamic, based upon settings
485 * on the task or the task's handlers. Each operation should have a type. In
486 * addition to all the types allowed in page_manager_render_operations, these
487 * types will be dynamically replaced with something else:
488 * - 'handlers': An automatically created group that contains all the task's
489 * handlers and appropriate links.
490 * - 'function': A callback (which will be placed in the 'function' parameter
491 * that should return an array of operations. This can be used to provide
492 * additional, dynamic links if needed.
494 function page_manager_get_operations($page, $operations = NULL) {
495 if (!isset($operations)) {
496 // All tasks have at least these 2 ops:
499 'title' => t('Summary'),
500 'description' => t('Get a summary of the information about this page.'),
501 'path' => 'admin/structure/pages/edit',
503 'no operations' => TRUE,
504 'form info' => array(
505 'no buttons' => TRUE,
507 'form' => 'page_manager_page_summary',
512 'class' => array('operations-actions'),
513 'location' => 'primary',
514 'children' => array(),
518 if (isset($page->subtask['operations'])) {
519 $operations += $page->subtask['operations'];
520 // add actions separately.
521 if (!empty($page->subtask['operations']['actions'])) {
522 $operations['actions']['children'] += $page->subtask['operations']['actions']['children'];
525 $operations['handlers'] = array('type' => 'handlers');
529 foreach ($operations as $id => $operation) {
530 if (empty($operation['type'])) {
531 $operation['type'] = 'operation';
533 switch ($operation['type']) {
535 $result[$id] = page_manager_get_handler_operations($page);
538 if (function_exists($operation['function'])) {
539 $retval = $function($page, $operation);
540 if (is_array($retval)) {
541 $result[$id] = $retval;
546 $result[$id] = $operation;
550 if (!empty($page->subtask['enable callback']) && !empty($page->subtask['disabled']) && empty($result['actions']['children']['enable'])) {
551 $result['actions']['children']['enable'] = array(
552 'title' => t('Enable'),
553 'description' => t('Activate this page so that it will be in use in your system.'),
554 'form' => 'page_manager_enable_form',
557 'no update and save' => TRUE,
558 'form info' => array(
559 'finish text' => t('Enable'),
564 if (!empty($page->subtask['enable callback']) && empty($page->subtask['disabled']) && empty($result['actions']['children']['disable'])) {
565 $result['actions']['children']['disable'] = array(
566 'title' => t('Disable'),
567 'description' => t('De-activate this page. The data will remain but the page will not be in use on your system.'),
568 'form' => 'page_manager_disable_form',
571 'no update and save' => TRUE,
572 'form info' => array(
573 'finish text' => t('Disable'),
578 $result['actions']['children']['add'] = array(
579 'title' => t('Add variant'),
580 'description' => t('Add a new variant to this page.'),
581 'form' => 'page_manager_handler_add',
583 'silent' => TRUE, // prevents a message about updating and prevents this item from showing as changed.
584 'no update and save' => TRUE, // get rid of update and save button which is bad here.
585 'form info' => array(
586 'finish text' => t('Create variant'),
590 // Restrict variant import due to security implications.
591 if (user_access('use ctools import')) {
592 $result['actions']['children']['import'] = array(
593 'title' => t('Import variant'),
594 'description' => t('Add a new variant to this page from code exported from another page.'),
595 'form' => 'page_manager_handler_import',
599 if (count($page->handlers) > 1) {
600 $result['actions']['children']['rearrange'] = array(
601 'title' => t('Reorder variants'),
603 'description' => t('Change the priority of the variants to ensure that the right one gets selected.'),
604 'form' => 'page_manager_handler_rearrange',
608 // This is a special operation used to configure a new task handler before
610 if (isset($page->new_handler)) {
611 $plugin = page_manager_get_task_handler($page->new_handler->handler);
612 $result['actions']['children']['configure'] = array(
613 'title' => t('Configure'),
614 'description' => t('Configure a newly created variant prior to actually adding it to the page.'),
616 'no update and save' => TRUE, // get rid of update and save button which is bad here.
617 'form info' => array(
618 // We use our own cancel and finish callback to handle the fun stuff.
619 'finish callback' => 'page_manager_handler_add_finish',
620 'cancel callback' => 'page_manager_handler_add_cancel',
621 'show trail' => TRUE,
623 'finish text' => t('Create variant'),
626 'forms' => $plugin['forms'],
630 foreach ($page->forms as $id) {
631 if (isset($plugin['add features'][$id])) {
632 $result['actions']['children']['configure']['form']['order'][$id] = $plugin['add features'][$id];
634 else if (isset($plugin['required forms'][$id])) {
635 $result['actions']['children']['configure']['form']['order'][$id] = $plugin['required forms'][$id];
641 $result['actions']['children']['break-lock'] = array(
642 'title' => t('Break lock'),
643 'description' => t('Break the lock on this page so that you can edit it.'),
644 'form' => 'page_manager_break_lock',
646 'no update and save' => TRUE, // get rid of update and save button which is bad here.
647 'form info' => array(
648 'finish text' => t('Break lock'),
650 'even locked' => TRUE, // show button even if locked
655 drupal_alter('page_manager_operations', $result, $page);
660 * Collect all the operations related to task handlers (variants) and
663 function page_manager_get_handler_operations(&$page) {
664 ctools_include('export');
667 'class' => array('operations-handlers'),
668 'title' => t('Variants'),
671 $operations = array();
673 // If there is only one variant, let's not have it collapsible.
674 $collapsible = count($page->handler_info) != 1;
675 foreach ($page->handler_info as $id => $info) {
676 if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
679 $handler = $page->handlers[$id];
680 $plugin = page_manager_get_task_handler($handler->handler);
682 $operations[$id] = array(
684 'class' => array('operations-handlers-' . $id),
685 'title' => page_manager_get_handler_title($plugin, $handler, $page->task, $page->subtask_id),
686 'collapsible' => $collapsible,
687 'children' => array(),
690 $operations[$id]['children']['actions'] = array(
692 'class' => array('operations-handlers-actions-' . $id),
693 'title' => t('Variant operations'),
694 'children' => array(),
698 // There needs to be a 'summary' item here for variants.
699 $operations[$id]['children']['summary'] = array(
700 'title' => t('Summary'),
701 'description' => t('Get a summary of the information about this variant.'),
702 'form info' => array(
703 'no buttons' => TRUE,
705 'form' => 'page_manager_handler_summary',
708 if ($plugin && isset($plugin['operations'])) {
709 $operations[$id]['children'] += $plugin['operations'];
712 $actions = &$operations[$id]['children']['actions']['children'];
714 $actions['clone'] = array(
715 'title' => t('Clone'),
716 'description' => t('Make an exact copy of this variant.'),
717 'form' => 'page_manager_handler_clone',
719 $actions['export'] = array(
720 'title' => t('Export'),
721 'description' => t('Export this variant into code to import into another page.'),
722 'form' => 'page_manager_handler_export',
724 if ($handler->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
725 $actions['delete'] = array(
726 'title' => t('Revert'),
727 'description' => t('Remove all changes to this variant and revert to the version in code.'),
728 'form' => 'page_manager_handler_delete',
729 'no update and save' => TRUE,
730 'form info' => array(
731 'finish text' => t('Revert'),
735 else if ($handler->export_type != EXPORT_IN_CODE) {
736 $actions['delete'] = array(
737 'title' => t('Delete'),
738 'description' => t('Remove this variant from the page completely.'),
739 'form' => 'page_manager_handler_delete',
740 'form info' => array(
741 'finish text' => t('Delete'),
742 'save text' => t('Delete and save'),
746 if (!empty($handler->disabled)) {
747 $actions['enable'] = array(
748 'title' => t('Enable'),
749 'description' => t('Activate this variant so that it will be in use in your system.'),
750 'form' => 'page_manager_handler_enable',
752 'form info' => array(
753 'finish text' => t('Enable'),
754 'save text' => t('Enable and save'),
759 $actions['disable'] = array(
760 'title' => t('Disable'),
761 'description' => t('De-activate this variant. The data will remain but the variant will not be in use on your system.'),
762 'form' => 'page_manager_handler_disable',
764 'form info' => array(
765 'finish text' => t('Disable'),
766 'save text' => t('Disable and save'),
771 drupal_alter('page_manager_variant_operations', $operations[$id], $handler);
773 if (empty($operations)) {
774 $operations['empty'] = array(
776 'title' => t('No variants'),
780 $group['children'] = $operations;
785 * Get an operation from a trail.
787 * @return array($operation, $active, $args)
789 function page_manager_get_operation($operations, $trail) {
794 // Drill down into operations array:
796 $check = reset($args);
798 if (is_array($operations)) {
799 if (isset($operations[$check])) {
801 $operation = array_shift($args);
802 // check to see if this operation has children. If so, we continue.
803 if (!isset($operations[$check]['children'])) {
804 $operations = $operations[$check];
807 $titles[] = $operations[$check]['title'];
808 $operations = $operations[$check]['children'];
809 // continue only if the operation hs children.
816 return array($operations, $active, $args, $titles);
820 * Fetch the content for an operation.
822 * First, this drills down through the arguments to find the operation, and
823 * turns whatever it finds into the active trail which is then used to
824 * hilite where we are when rendering the operation list.
826 * The arguments are discovered from the URL, and are an exact match for where
827 * the operation is in the hierarchy. For example, handlers/foo/settings will
828 * be the operation to edit the settings for the handler named foo. This comes
829 * in as an array ('handlers', 'foo', 'settings') and is used to find where the
830 * data for that operation is in the array.
832 function page_manager_get_operation_content($js, &$page, $trail, $operations) {
833 list($operation, $active, $args, $titles) = page_manager_get_operation($operations, $trail);
834 // Once we've found the operation, send it off to render.
836 $content = _page_manager_get_operation_content($js, $page, $active, $operation, $titles, $args);
839 if (empty($content)) {
840 $content = _page_manager_get_operation_content($js, $page, array('summary'), $operations['summary']);
847 * Fetch the content for an operation, after it's been discovered from arguments.
849 * This system runs through the CTools form wizard. Each operation specifies a form
850 * or set of forms that it may use. Operations may also specify wrappers and can
851 * set their own next/finish handlers so that they can make additional things happen
854 function _page_manager_get_operation_content($js, &$page, $active, $operation, $titles = array(), $args = array()) {
855 if (isset($operation['form'])) {
857 'id' => 'page_manager_page',
858 'finish text' => t('Update'),
859 'show trail' => FALSE,
860 'show back' => FALSE,
861 'show return' => FALSE,
862 'show cancel' => FALSE,
863 'next callback' => 'page_manager_edit_page_next',
864 'finish callback' => 'page_manager_edit_page_finish',
865 // Items specific to the 'edit' routines that will get moved over:
866 'path' => page_manager_edit_url($page->task_name, $active) . "/%step",
867 // wrapper function to add an extra finish button.
868 'wrapper' => 'page_manager_operation_wrapper',
871 // If $operation['form'] is simply a string, then it is the function
873 if (!is_array($operation['form'])) {
874 $form_info['order'] = array(
875 'form' => $operation['title'],
877 $form_info['forms'] = array(
878 'form' => array('form id' => $operation['form']),
880 if (isset($operation['wrapper'])) {
881 $form_info['forms']['form']['wrapper'] = $operation['wrapper'];
884 // Otherwise it's the order and forms arrays directly.
886 $form_info['order'] = $operation['form']['order'];
887 $form_info['forms'] = $operation['form']['forms'];
890 // Allow the operation to override any form info settings:
891 if (isset($operation['form info'])) {
892 foreach ($operation['form info'] as $key => $setting) {
893 $form_info[$key] = $setting;
897 if (!empty($page->subtask['operations include'])) {
898 // Quickly load any files necessary to display the forms.
899 $page->subtask['operations include']['function'] = 'nop';
900 ctools_plugin_get_function($page->subtask, 'operations include');
903 $step = array_shift($args);
904 // If step is unset, go with the basic step.
906 $step = current(array_keys($form_info['order']));
909 // If it is locked, hide the buttonzzz!
910 if ($page->locked && empty($operation['even locked'])) {
911 $form_info['no buttons'] = TRUE;
914 ctools_include('wizard');
918 'ajax' => $js && (!isset($operation['ajax']) || !empty($operation['ajax'])),
921 'task_name' => $page->task_name,
922 'task_id' => $page->task_id,
923 'task' => $page->task,
924 'subtask_id' => $page->subtask_id,
925 'subtask' => $page->subtask,
926 'operation' => $operation,
929 if ($active && $active[0] == 'handlers' && isset($form_state['page']->handlers[$form_state['trail'][1]])) {
930 $form_state['handler_id'] = $form_state['trail'][1];
931 $form_state['handler'] = &$form_state['page']->handlers[$form_state['handler_id']];
934 if ($active && $active[0] == 'actions' && $active[1] == 'configure' && isset($form_state['page']->new_handler)) {
935 $form_state['handler_id'] = $form_state['page']->new_handler->name;
936 $form_state['handler'] = &$form_state['page']->new_handler;
939 $built_form = ctools_wizard_multistep_form($form_info, $step, $form_state);
940 $output = drupal_render($built_form);
941 $title = empty($form_state['title']) ? $operation['title'] : $form_state['title'];
943 $title = implode(' » ', array_filter($titles));
945 // If there are messages for the form, render them.
946 if ($messages = theme('status_messages')) {
947 $output = $messages . $output;
950 $description = isset($operation['admin description']) ? $operation['admin description'] : (isset($operation['description']) ? $operation['description'] : '');
953 'content' => $output,
954 'description' => $description,
957 // Append any extra content, used for the preview which is submitted then
959 if (isset($form_state['content'])) {
960 $return['content'] .= $form_state['content'];
963 // If the form wanted us to go somewhere else next, pass that along.
964 if (isset($form_state['new trail'])) {
965 $return['new trail'] = $form_state['new trail'];
970 'title' => t('Error'),
971 'content' => t('This operation trail does not exist.'),
975 $return['active'] = $active;
979 function page_manager_operation_wrapper($form, &$form_state) {
980 if (empty($form_state['operation']['no update and save']) && !empty($form['buttons']['return']['#wizard type']) && $form['buttons']['return']['#wizard type']) {
981 $form['buttons']['save'] = array(
983 '#value' => !empty($form_state['form_info']['save text']) ? $form_state['form_info']['save text'] : t('Update and save'),
984 '#wizard type' => 'finish',
985 '#attributes' => $form['buttons']['return']['#attributes'],
994 * Callback generated when the an operation edit finished.
996 function page_manager_edit_page_finish(&$form_state) {
997 if (empty($form_state['operation']['silent'])) {
998 if (empty($form_state['clicked_button']['#save'])) {
999 drupal_set_message(t('The page has been updated. Changes will not be permanent until you save.'));
1002 drupal_set_message(t('The page has been updated and saved.'));
1005 foreach ($form_state['trail'] as $operation) {
1006 $path[] = $operation;
1007 $form_state['page']->changes[implode('/', $path)] = TRUE;
1011 // If a handler was modified, set it to changed so we know to overwrite it.
1012 if (isset($form_state['handler_id'])) {
1013 $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_CACHED;
1016 // While we make buttons go away on locked pages, it is still possible to
1017 // have a lock a appear while you were editing, and have your changes
1018 // disappear. This at least warns the user that this has happened.
1019 if (!empty($page->locked)) {
1020 drupal_set_message(t('Unable to update changes due to lock.'));
1023 // If the 'Update and Save' button was selected, write our cache out.
1024 if (!empty($form_state['clicked_button']['#save'])) {
1025 page_manager_save_page_cache($form_state['page']);
1026 page_manager_clear_page_cache($form_state['page']->task_name);
1027 $form_state['page'] = page_manager_get_page_cache($form_state['page']->task_name);
1030 if (empty($form_state['do not cache'])) {
1031 page_manager_set_page_cache($form_state['page']);
1035 // We basically always want to force a rerender when the forms
1036 // are finished, so make sure there is a new trail.
1037 if (empty($form_state['new trail'])) {
1038 // force a rerender to get rid of old form items that may have changed
1040 $form_state['new trail'] = $form_state['trail'];
1043 if (isset($form_state['new trail']) && empty($form_state['ajax'])) {
1044 $form_state['redirect'] = page_manager_edit_url($form_state['page']->task_name, $form_state['new trail']);
1047 $form_state['complete'] = TRUE;
1051 * Callback generated when the 'next' button is clicked.
1053 * All we do here is store the cache.
1055 function page_manager_edit_page_next(&$form_state) {
1056 page_manager_set_page_cache($form_state['page']);
1060 * Callback generated when the 'cancel' button is clicked.
1062 * All we do here is clear the cache.
1064 function page_manager_edit_page_cancel(&$form_state) {
1065 $page = $form_state['page'];
1069 * Render an operations array.
1071 * This renders an array of operations into a series of nested UL statements,
1072 * with ajax automatically on unless specified otherwise. Operations will
1073 * automatically have the URLs generated nested.
1075 * Each operation should have a 'type', which tells the renderer how to deal
1077 * - 'operation': An AJAX link to render. This is the default and is
1078 * assumed if a type is not specified. Other fields for the operation:
1079 * - - 'title': The text to display. Can be an image. Must be pre-sanitized.
1080 * - - 'description': Text to place in the hover box over the link using the
1082 * - - 'arguments': Anything optional to put at the end of the URL.
1083 * - - 'path': If set, overrides the default path.
1084 * - - 'no operations': If set, the path will not have operations appended.
1085 * - - 'no task': If set, the path will not have the task id.
1086 * - - 'no link': If set, this item will just be text, not a link.
1087 * - - 'ajax': If set to TRUE, ajax will be used. The default is TRUE.
1088 * - - 'class': An optional class to specify for the link.
1089 * - - 'form': The form to display for this operation, if using a single form.
1090 * - - 'forms': An array of forms that must be paired with 'order' of this
1091 * operation uses multiple forms. See wizard tool for details.
1092 * - - 'order': The form order to use for multiple forms. See wizard tool for
1094 * - - 'form info': Form info overrides for the wizard. See the wizard tool
1095 * for available settings
1097 * - - 'title': The title of the link. May be HTML.
1098 * - - 'title class': A class to apply to the title.
1099 * - - 'children': An array of more operations that this group represents.
1100 * All operations within this group will have this group's ID as part
1101 * of the AJAX url to make it easier to find.
1102 * - - 'class': A class to apply to the UL of the children.
1103 * - - 'collapsible': If TRUE the collapsible tool will be used.
1105 function page_manager_render_operations(&$page, $operations, $active_trail, $attributes, $location, $parents = array()) {
1106 drupal_add_library('system', 'drupal.ajax');
1108 if (!isset($output[$location])) {
1109 $output[$location] = '';
1112 $keys = array_keys($operations);
1113 $first = array_shift($keys);
1114 $last = array_pop($keys);
1116 // Make sure the 'first' and 'last' operations are part of THIS nav tree:
1117 while ($keys && isset($operations[$first]['location']) && $operations[$first]['location'] != $location) {
1118 $first = array_shift($keys);
1120 while ($keys && isset($operations[$last]['location']) && $operations[$last]['location'] != $location) {
1121 $last = array_pop($keys);
1124 $active = reset($active_trail);
1125 foreach ($operations as $id => $operation) {
1128 $current_path .= implode('/', $parents) . '/';
1130 $current_path .= $id;
1132 if (empty($operation['type'])) {
1133 $operation['type'] = 'operation';
1136 // We only render an li for things in the same nav tree.
1137 if (empty($operation['location']) || $operation['location'] == $location) {
1138 if (!is_array($attributes['class'])) {
1139 $attributes['class'] = array($attributes['class']);
1142 $class = empty($attributes['class']) || !is_array($attributes['class']) ? array() : $attributes['class'];
1144 if ($id == $first) {
1145 $class[] = 'operation-first';
1147 else if ($id == $last) {
1148 $class[] = 'operation-last';
1151 if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
1152 $class[] = $operation['type'] == 'group' ? 'changed-group' : 'changed';
1155 $class[] = 'not-changed';
1158 if ($active == $id) {
1159 $class[] = $operation['type'] == 'group' ? 'active-group' : 'active';
1162 $class[] = 'not-active';
1165 $output[$location] .= '<li class="' . implode(' ', $class) . '">';
1168 switch ($operation['type']) {
1170 $output[$location] .= $operation['title'];
1173 $path = isset($operation['path']) ? $operation['path'] : 'admin/structure/pages/nojs/operation';
1174 if (!isset($operation['no task'])) {
1175 $path .= '/' . $page->task_name;
1178 if (!isset($operation['no operations'])) {
1179 $path .= '/' . $current_path;
1180 if (isset($operation['arguments'])) {
1181 $path .= '/' . $arguments;
1185 $class = array('page-manager-operation');
1186 if (!isset($operation['ajax']) || !empty($operation['ajax'])) {
1187 $class[] = 'use-ajax';
1189 if (!empty($operation['class'])) {
1190 $class[] = $operation['class'];
1193 $description = isset($operation['description']) ? $operation['description'] : '';
1194 if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
1195 $description .= ' ' . t('This setting contains unsaved changes.');
1198 $output[$location] .= l($operation['title'], $path, array('attributes' => array('id' => 'page-manager-operation-' . $id, 'class' => $class, 'title' => $description), 'html' => TRUE));
1201 if ($active == $id) {
1202 $trail = $active_trail;
1203 array_shift($trail);
1208 $group_location = isset($operation['location']) ? $operation['location'] : $location;
1209 $temp = page_manager_render_operations($page, $operation['children'], $trail, $operation, $group_location, array_merge($parents, array($id)));
1211 foreach ($temp as $id => $text) {
1212 if (empty($output[$id])) {
1215 $output[$id] .= $text;
1221 if (empty($operation['location']) || $operation['location'] == $location) {
1222 $output[$location] .= '</li>';
1226 if ($output[$location]) {
1227 $classes = isset($attributes['class']) && is_array($attributes['class']) ? $attributes['class'] : array();
1228 $classes[] = 'page-manager-operations';
1230 $output[$location] = '<ul class="' . implode(' ', $classes) . '">' . $output[$location] . '</ul>';
1232 if (!empty($attributes['title'])) {
1234 if (isset($attributes['title class'])) {
1235 $class = $attributes['title class'];
1237 $title = '<div class="page-manager-group-title' . $class . '">' . $attributes['title'] . '</div>';
1239 if (!empty($attributes['collapsible'])) {
1240 $output[$location] = theme('ctools_collapsible', array('handle' => $title, 'content' => $output[$location], 'collapsed' => empty($active_trail)));
1243 $output[$location] = $title . $output[$location];
1251 * Provide a simple form for saving the page manager info out of the cache.
1253 function page_manager_save_page_form($form, &$form_state) {
1254 if (!empty($form_state['page']->changed)) {
1255 $form['markup'] = array(
1256 '#markup' => '<div class="changed-notification">' . t('You have unsaved changes to this page. You must select Save to write them to the database, or Cancel to discard these changes. Please note that if you have changed any form, you must submit that form before saving.') . '</div>',
1259 // Always make sure we submit back to the proper page.
1260 $form['#action'] = url('admin/structure/pages/edit/' . $form_state['page']->task_name);
1261 $form['save'] = array(
1262 '#type' => 'submit',
1263 '#value' => t('Save'),
1264 '#submit' => array('page_manager_save_page_form_submit'),
1267 $form['cancel'] = array(
1268 '#type' => 'submit',
1269 '#value' => t('Cancel'),
1270 '#submit' => array('page_manager_save_page_form_cancel'),
1279 function page_manager_save_page_form_submit(&$form, &$form_state) {
1280 page_manager_save_page_cache($form_state['page']);
1284 * Discard changes to the page.
1286 function page_manager_save_page_form_cancel($form, &$form_state) {
1287 drupal_set_message(t('All pending changes have been discarded, and the page is now unlocked.'));
1288 page_manager_clear_page_cache($form_state['page']->task_name);
1290 if (!empty($form_state['page']->new)) {
1291 $form_state['redirect'] = 'admin/structure/pages';
1295 // --------------------------------------------------------------------------
1296 // Handler (variant) related forms.
1299 * Add a new task handler.
1301 function page_manager_handler_add($form, &$form_state) {
1302 // Get a list of possible task handlers for this task.
1303 return page_manager_handler_add_form($form, $form_state);
1307 * Handler related forms.
1309 function page_manager_handler_add_submit(&$form, &$form_state) {
1310 $cache = $form_state['page'];
1311 $plugin = page_manager_get_task_handler($form_state['values']['handler']);
1313 // Create a new handler.
1314 $handler = page_manager_new_task_handler($plugin);
1315 if (!empty($form_state['values']['title'])) {
1316 $handler->conf['title'] = $form_state['values']['title'];
1319 $handler->conf['title'] = $plugin['title'];
1321 $handler->conf['name'] = $form_state['values']['name'];
1322 $cache->new_handler = $handler;
1324 // Figure out which forms to present them with
1325 $cache->forms = array();
1327 $features = $form_state['values']['features'];
1328 if (isset($features[$form_state['values']['handler']])) {
1329 $cache->forms = array_merge($cache->forms, array_keys(array_filter($features[$form_state['values']['handler']])));
1332 if (isset($plugin['required forms'])) {
1333 $cache->forms = array_merge($cache->forms, array_keys($plugin['required forms']));
1336 $form_state['no_rerender'] = TRUE;
1337 if (!empty($cache->forms)) {
1338 // Tell the form to go to the config page.
1339 drupal_set_message(t('Before this variant can be added, it must be configured. When you are finished, click "Create variant" at the end of this wizard to add this to your page.'));
1340 $form_state['new trail'] = array('actions', 'configure');
1343 // It has no forms at all. Add the variant and go to its first operation.
1344 page_manager_handler_add_finish($form_state);
1349 * Finish the add process and make the new handler official.
1351 function page_manager_handler_add_finish(&$form_state) {
1352 $page = &$form_state['page'];
1353 $handler = $page->new_handler;
1354 page_manager_handler_add_to_page($page, $handler);
1356 // Remove the temporary page.
1357 unset($page->new_handler);
1358 unset($page->forms);
1360 // Set the new destination
1361 $plugin = page_manager_get_task_handler($handler->handler);
1362 if (!empty($plugin['add finish'])) {
1363 $location = $plugin['add finish'];
1366 $keys = array_keys($plugin['operations']);
1367 $location = reset($keys);
1370 $form_state['new trail'] = array('handlers', $handler->name, $location);
1373 page_manager_edit_page_finish($form_state);
1377 * Throw away a new handler and return to the add form
1379 function page_manager_handler_add_cancel(&$form_state) {
1380 $form_state['new trail'] = array('handlers', 'add');
1382 // Remove the temporary page.
1383 unset($page->new_handler);
1384 unset($page->forms);
1388 * Provide a consistent UI for adding handlers.
1390 function page_manager_handler_add_form($form, $form_state, $features = array()) {
1391 $task = $form_state['task'];
1392 $task_handler_plugins = page_manager_get_task_handler_plugins($task);
1393 if (empty($task_handler_plugins)) {
1394 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');
1395 $form['buttons']['return']['#disabled'] = TRUE;
1399 foreach ($task_handler_plugins as $id => $plugin) {
1400 $options[$id] = $plugin['title'];
1401 if (isset($plugin['add features'])) {
1402 $features[$id] = $plugin['add features'];
1406 if (!isset($form_state['type']) || $form_state['type'] != 'add') {
1407 $form['title'] = array(
1408 '#type' => 'textfield',
1409 '#title' => t('Title'),
1410 '#description' => t('Administrative title of this variant. If you leave blank it will be automatically assigned.'),
1413 $form['name'] = array(
1414 '#type' => 'machine_name',
1415 '#title' => t('Machine name'),
1416 '#required' => FALSE,
1417 '#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."),
1420 '#machine_name' => array(
1421 'exists' => 'page_manager_handler_check_machine_name',
1422 'source' => array('title'),
1424 '#field_prefix' => '<span dir="ltr">' . $form_state['task_name'] . '__',
1425 '#field_suffix' => '</span>‎',
1429 $form['handler'] = array(
1430 '#title' => t('Variant type'),
1431 '#type' => 'select',
1432 '#options' => $options,
1435 // This set of checkboxes is not dangerous at all.
1436 $form['features'] = array(
1438 '#title' => t('Optional features'),
1439 '#description' => t('Check any optional features you need to be presented with forms for configuring them. If you do not check them here you will still be able to utilize these features once the new page is created. If you are not sure, leave these unchecked.'),
1443 ctools_include('dependent');
1444 foreach ($features as $plugin => $feature_list) {
1445 foreach ($feature_list as $feature_id => $feature) {
1446 $form['features'][$plugin][$feature_id] = array(
1447 '#type' => 'checkbox',
1448 '#title' => $feature,
1450 if (!empty($form_state['page']->forms) && in_array($feature_id, $form_state['page']->forms)) {
1451 $form['features'][$plugin][$feature_id]['#default_value'] = TRUE;
1454 if ($plugin != 'default') {
1455 $form['features'][$plugin][$feature_id] += array(
1456 '#dependency' => array('edit-handler' => array($plugin)),
1466 * Check if handler's machine-name is unique
1468 function page_manager_handler_check_machine_name($name, $element, $form_state) {
1469 $name = $form_state['task_name'] . '__' . $name;
1471 return count(ctools_export_load_object('page_manager_handlers', 'names', array($name)));
1475 * Rearrange the order of variants.
1477 function page_manager_handler_import($form, &$form_state) {
1478 $form['title'] = array(
1479 '#type' => 'textfield',
1480 '#title' => t('Variant name'),
1481 '#description' => t('Enter the name of the new variant.'),
1484 if (user_access('use ctools import')) {
1485 $form['object'] = array(
1486 '#type' => 'textarea',
1487 '#title' => t('Paste variant code here'),
1491 // Users ordinarily can't get here without the 'import' permission, due to
1492 // security implications. In case they somehow do, though, disable the form
1493 // widget for extra safety.
1495 $form['shoveoff'] = array(
1496 '#markup' => '<div>' . t('You do not have sufficient permissions to perform this action.') . '</div>',
1504 * Make sure that an import actually provides a handler.
1506 function page_manager_handler_import_validate($form, &$form_state) {
1507 if (!user_access('use ctools import')) {
1508 form_error($form['shoveoff'], t('You account permissions do not permit you to import.'));
1512 eval($form_state['values']['object']);
1515 if (empty($handler)) {
1516 $errors = ob_get_contents();
1517 if (empty($errors)) {
1518 $errors = t('No variant found.');
1521 form_error($form['object'], t('Unable to get a variant from the import. Errors reported: @errors', array('@errors' => $errors)));
1524 $form_state['handler'] = $handler;
1528 * Clone an existing task handler into a new handler.
1530 function page_manager_handler_import_submit(&$form, &$form_state) {
1531 $handler = $form_state['handler'];
1533 page_manager_handler_add_to_page($form_state['page'], $handler, $form_state['values']['title']);
1535 $plugin = page_manager_get_task_handler($handler->handler);
1536 // It has no forms at all. Add the variant and go to its first operation.
1537 $keys = array_keys($plugin['operations']);
1538 $form_state['new trail'] = array('handlers', $handler->name, reset($keys));
1542 * Rearrange the order of variants.
1544 function page_manager_handler_rearrange($form, &$form_state) {
1545 $page = $form_state['page'];
1547 $form['handlers'] = array('#tree' => TRUE);
1549 foreach ($page->handler_info as $id => $info) {
1550 if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
1553 $handler = $page->handlers[$id];
1554 $plugin = page_manager_get_task_handler($handler->handler);
1556 $form['handlers'][$id]['title'] = array(
1557 '#markup' => page_manager_get_handler_title($plugin, $handler, $page->task, $page->subtask_id),
1560 $form['handlers'][$id]['weight'] = array(
1561 '#type' => 'weight',
1562 '#default_value' => $info['weight'],
1570 function page_manager_handler_rearrange_submit(&$form, &$form_state) {
1571 $handler_info = &$form_state['page']->handler_info;
1573 foreach ($form_state['values']['handlers'] as $id => $info) {
1574 if ($handler_info[$id]['weight'] = $info['weight']) {
1575 $handler_info[$id]['weight'] = $info['weight'];
1576 $handler_info[$id]['changed'] |= PAGE_MANAGER_CHANGED_MOVED;
1580 // Sort the new cache.
1581 uasort($handler_info, '_page_manager_handler_sort');
1586 * Used as a callback to uasort to sort the task cache by weight.
1588 * The 'name' field is used as a backup when weights are the same, which
1589 * can happen when multiple modules put items out there at the same
1592 function _page_manager_handler_sort($a, $b) {
1593 if ($a['weight'] < $b['weight']) {
1596 elseif ($a['weight'] > $b['weight']) {
1599 elseif ($a['name'] < $b['name']) {
1602 elseif ($a['name'] > $b['name']) {
1608 * Rearrange the order of variants.
1610 function page_manager_handler_delete($form, &$form_state) {
1611 if ($form_state['handler']->type == t('Overridden')) {
1612 $text = t('Reverting the variant will delete the variant that is in the database, reverting it to the original default variant. This deletion will not be made permanent until you click Save.');
1615 $text = t('Are you sure you want to delete this variant? This deletion will not be made permanent until you click Save.');
1617 $form['markup'] = array(
1618 '#markup' => '<p>' . $text . '</p>',
1625 * Submit handler to delete a view.
1627 function page_manager_handler_delete_submit(&$form, &$form_state) {
1628 $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_DELETED;
1629 $form_state['new trail'] = array('summary');
1633 * Entry point to export a page.
1635 function page_manager_handler_export($form, &$form_state) {
1636 $export = page_manager_export_task_handler($form_state['handler']);
1638 $lines = substr_count($export, "\n");
1639 $form['code'] = array(
1640 '#type' => 'textarea',
1641 '#default_value' => $export,
1645 unset($form['buttons']);
1650 * Rearrange the order of variants.
1652 function page_manager_handler_clone($form, &$form_state) {
1653 // This provides its own button because it does something totally different.
1654 $form['title'] = array(
1655 '#type' => 'textfield',
1656 '#title' => t('Variant name'),
1657 '#description' => t('Enter the name of the new variant.'),
1664 * Clone an existing task handler into a new handler.
1666 function page_manager_handler_clone_submit(&$form, &$form_state) {
1667 $export = page_manager_export_task_handler($form_state['handler']);
1672 page_manager_handler_add_to_page($form_state['page'], $handler, $form_state['values']['title']);
1674 $plugin = page_manager_get_task_handler($handler->handler);
1675 // It has no forms at all. Add the variant and go to its first operation.
1676 $keys = array_keys($plugin['operations']);
1677 $form_state['new trail'] = array('handlers', $handler->name, reset($keys));
1681 * Form to enable a handler.
1683 function page_manager_handler_enable($form, &$form_state) {
1684 $form['markup'] = array(
1685 '#markup' => t('This variant is currently disabled. Enabling it will make it available in your system. This will not take effect until you save this page.'),
1692 * Enable the page after it has been confirmed.
1694 function page_manager_handler_enable_submit(&$form, &$form_state) {
1695 $form_state['handler']->disabled = FALSE;
1696 $form_state['page']->handler_info[$form_state['handler_id']]['disabled'] = FALSE;
1697 $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_STATUS;
1698 $form_state['new trail'] = array('handlers', $form_state['handler_id'], 'actions', 'disable');
1702 * Form to disable a page.
1704 function page_manager_handler_disable($form, &$form_state) {
1705 $form['markup'] = array(
1706 '#markup' => t('This variant is currently enabled. Disabling it will make it unavailable in your system, and it will not be used. This will not take effect until you save this page.'),
1713 * Form to disable a page.
1715 function page_manager_handler_summary($form, &$form_state) {
1716 $handler = $form_state['handler'];
1717 $page = $form_state['page'];
1718 $plugin = page_manager_get_task_handler($handler->handler);
1720 $form['markup'] = array(
1721 '#markup' => page_manager_get_handler_summary($plugin, $handler, $page, FALSE),
1728 * Disable the page after it has been confirmed.
1730 function page_manager_handler_disable_submit(&$form, &$form_state) {
1731 $form_state['handler']->disabled = TRUE;
1732 $form_state['page']->handler_info[$form_state['handler_id']]['disabled'] = TRUE;
1733 $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_STATUS;
1734 $form_state['new trail'] = array('handlers', $form_state['handler_id'], 'actions', 'enable');
1738 * Break the lock on a page so that it can be edited.
1740 function page_manager_break_lock($form, &$form_state) {
1741 $form['markup'] = array(
1742 '#markup' => t('Breaking the lock on this page will <strong>discard</strong> any pending changes made by the locking user. Are you REALLY sure you want to do this?')
1749 * Submit to break the lock on a page.
1751 function page_manager_break_lock_submit(&$form, &$form_state) {
1752 $page = &$form_state['page'];
1753 $form_state['page']->locked = FALSE;
1754 ctools_object_cache_clear_all('page_manager_page', $page->task_name);
1755 $form_state['do not cache'] = TRUE;
1756 drupal_set_message(t('The lock has been cleared and all changes discarded. You may now make changes to this page.'));
1758 $form_state['new trail'] = array('summary');
1762 * Form to enable a page.
1764 function page_manager_enable_form($form, &$form_state) {
1765 $form['markup'] = array(
1766 '#markup' => t('Enabling this page will immediately make it available in your system (there is no need to wait for a save.)'),
1773 * Enable the page after it has been confirmed.
1775 function page_manager_enable_form_submit(&$form, &$form_state) {
1776 $page = &$form_state['page'];
1777 if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
1778 $result = $function($page, FALSE);
1781 $form_state['new trail'] = array('actions', 'disable');
1783 // We don't want to cause this to cache if it wasn't already. If it was
1784 // cached, however, we want to update the enabled state.
1785 if (empty($form_state['page']->changed)) {
1786 $form_state['do not cache'] = TRUE;
1791 * Form to disable a page.
1793 function page_manager_disable_form($form, &$form_state) {
1794 $form['markup'] = array(
1795 '#markup' => t('Disabling this page will immediately make it unavailable in your system (there is no need to wait for a save.)'),
1802 * Disable the page after it has been confirmed.
1804 function page_manager_disable_form_submit(&$form, &$form_state) {
1805 $page = &$form_state['page'];
1806 if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
1807 $result = $function($page, TRUE);
1809 $form_state['new trail'] = array('actions', 'enable');
1811 // We don't want to cause this to cache if it wasn't already. If it was
1812 // cached, however, we want to update the enabled state.
1813 if (empty($form_state['page']->changed)) {
1814 $form_state['do not cache'] = TRUE;
1820 * Print the summary information for a page.
1822 function page_manager_page_summary($form, &$form_state) {
1823 $page = $form_state['page'];
1828 if (isset($form_state['subtask']['admin title'])) {
1829 $form_state['title'] = $form_state['subtask']['admin title'];
1833 if (isset($form_state['subtask']['admin description'])) {
1834 $output .= '<div class="description">' . $form_state['subtask']['admin description'] . '</div>';
1837 $output .= page_manager_get_page_summary($page->task, $page->subtask);
1839 if (!empty($page->handlers)) {
1840 foreach ($page->handler_info as $id => $info) {
1841 if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
1845 $handler = $page->handlers[$id];
1846 $plugin = page_manager_get_task_handler($handler->handler);
1848 $output .= '<div class="handler-summary">';
1849 $output .= page_manager_get_handler_summary($plugin, $handler, $page);
1850 $output .= '</div>';
1855 $output .= '<p>' . t('This page has no variants and thus no output of its own.') . '</p>';
1860 'title' => ' » ' . t('Add a new variant'),
1861 'href' => page_manager_edit_url($page->task_name, array('actions', 'add')),
1866 $output .= '<div class="links">' . theme('links', array('links' => $links)) . '</div>';
1867 $form['markup'] = array(
1868 '#markup' => $output,
1875 * Menu callback to enable or disable a page
1877 function page_manager_enable_page($disable, $js, $page) {
1878 if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $page->task_name)) {
1879 return MENU_ACCESS_DENIED;
1881 if ($page->locked) {
1883 drupal_set_message(t('Unable to disable due to lock.'));
1886 drupal_set_message(t('Unable to enable due to lock.'));
1890 if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
1891 $result = $function($page, $disable);
1894 // We want to re-cache this if it's changed so that status is properly
1895 // updated on the changed form.
1896 if (!empty($page->changed)) {
1897 page_manager_set_page_cache($page);
1902 // For now $js is not actually in use on this.
1903 drupal_goto('admin/structure/pages');