xmlsitemap_modal.module

Tracking 7.x-2.x branch
  1. drupal
    1. 6 contributions/xmlsitemap/xmlsitemap_modal/xmlsitemap_modal.module
    2. 7 contributions/xmlsitemap/xmlsitemap_modal/xmlsitemap_modal.module

Functions & methods

NameDescription
xmlsitemap_modal_get_formDisplay a Drupal form using CTools modal or normal page display.
xmlsitemap_modal_menu_alterImplements hook_menu_alter().
xmlsitemap_modal_xmlsitemap_operation_link_alterImplements hook_xmlsitemap_operation_link_alter().

File

View source
  1. <?php
  2. /**
  3. * Implements hook_menu_alter().
  4. */
  5. function xmlsitemap_modal_menu_alter(&$items) {
  6. foreach ($items as $path => $item) {
  7. if (!empty($item['modal']) && strpos($path, '%ctools_js') === FALSE && $item['page callback'] ==='drupal_get_form') {
  8. $items["$path/%ctools_js"] = $item;
  9. $items["$path/%ctools_js"]['page callback'] = 'xmlsitemap_modal_get_form';
  10. $items["$path/%ctools_js"]['page arguments'][] = substr_count($path, '/') + 1;
  11. }
  12. }
  13. }
  14. /**
  15. * Display a Drupal form using CTools modal or normal page display.
  16. */
  17. function xmlsitemap_modal_get_form() {
  18. $args = func_get_args();
  19. $form_id = array_shift($args);
  20. $ajax = array_pop($args);
  21. if ($ajax) {
  22. ctools_include('ajax');
  23. ctools_include('modal');
  24. $form_state = array(
  25. 'ajax' => TRUE,
  26. 'args' => $args,
  27. );
  28. $commands = ctools_modal_form_wrapper($form_id, $form_state);
  29. if (empty($commands)) {
  30. $commands[] = ctools_modal_command_loading();
  31. if (!empty($_GET['destination'])) {
  32. $commands[] = ctools_ajax_command_redirect($_GET['destination']);
  33. }
  34. }
  35. return ajax_render($commands);
  36. //return ctools_ajax_render($commands);
  37. }
  38. else {
  39. array_unshift($args, $form_id);
  40. return call_user_func_array('drupal_get_form', $args);
  41. }
  42. }
  43. /**
  44. * Implements hook_xmlsitemap_operation_link_alter().
  45. */
  46. function xmlsitemap_modal_xmlsitemap_operation_link_alter(array &$link) {
  47. static $ctools_modal_included;
  48. // Process modal frame links.
  49. if (!empty($link['modal'])) {
  50. unset($link['modal']);
  51. if (!isset($ctools_modal_included)) {
  52. // Only process a few includes once per request.
  53. ctools_include('ajax');
  54. ctools_include('modal');
  55. ctools_modal_add_js();
  56. drupal_add_css(drupal_get_path('module', 'xmlsitemap_modal') . '/xmlsitemap_modal.css');
  57. }
  58. $link['attributes']['class'][] = 'ctools-use-modal';
  59. if (strpos($link['href'], 'nojs') === FALSE) {
  60. $link['href'] .= '/nojs';
  61. }
  62. else {
  63. $link['href'] = trim($link['href'], '/');
  64. }
  65. // @todo Remove when http://drupal.org/node/565808 is fixed.
  66. if (substr($link['href'], -4) === 'nojs') {
  67. $link['href'] .= '/';
  68. }
  69. }
  70. }