xmlsitemap_modal.module 2.2 KB

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