ctools_automodal_admin.module 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function ctools_automodal_admin_menu() {
  6. $items['admin/config/system/ctools_automodal_admin'] = array(
  7. 'title' => t('Ctools Automodal Settings'),
  8. 'page callback' => 'drupal_get_form',
  9. 'page arguments' => array('ctools_automodal_admin_admin_settings_form'),
  10. 'access arguments' => array('administer modules'),
  11. 'type' => MENU_NORMAL_ITEM,
  12. 'file' => 'includes/ctools_automodal_admin.admin.inc'
  13. );
  14. return $items;
  15. }
  16. function ctools_automodal_admin_init() {
  17. ctools_include('modal');
  18. ctools_modal_add_js();
  19. }
  20. /**
  21. * Implements hook_modal_paths() of ctools_automodal module.
  22. */
  23. function ctools_automodal_admin_menu_alter(&$items) {
  24. $paths = array();
  25. $automodal_paths = variable_get('ctools_automodal_admin_extra_paths', array());
  26. foreach ($automodal_paths as $item) {
  27. $items[$item]['modal'] = TRUE;
  28. }
  29. $modal_content_types = variable_get('ctools_automodal_admin_modal_content_types', array());
  30. foreach ($modal_content_types as $item) {
  31. $items[$item]['modal'] = TRUE;
  32. }
  33. return $paths;
  34. }
  35. /**
  36. * Implements hook_form_node_form_alter(&$form, &$form_state, $form_id).
  37. */
  38. function ctools_automodal_admin_form_node_form_alter(&$form, &$form_state, $form_id) {
  39. // Check if node form is automodal.
  40. // If it is, add own submit function.
  41. $node = $form_state['node'];
  42. $modal_content_types = variable_get('ctools_automodal_admin_modal_content_types', array());
  43. if (isset($modal_content_types[$node->type]) && $modal_content_types[$node->type]) {
  44. // Check if it's ajax request
  45. if (isset($_POST['js']) || isset($_POST['ajax_html_ids'])) {
  46. $form['actions']['submit']['#submit'][] = 'ctools_automodal_admin_add_content_submit';
  47. }
  48. }
  49. }
  50. function ctools_automodal_admin_add_content_submit($form, &$form_state) {
  51. // Call the rest of submits, because after this submit script will end.
  52. $submits = $form['actions']['submit']['#submit'];
  53. // Find the rest of submits.
  54. foreach ($submits as $key => $item) {
  55. unset($submits[$key]);
  56. if ($item == 'ctools_automodal_admin_add_content_submit') {
  57. break;
  58. }
  59. }
  60. // Call it.
  61. foreach ($submits as $function) {
  62. if (function_exists($function)) {
  63. $function($form, $form_state);
  64. }
  65. }
  66. // Redirect to destination, if set, or to node path.
  67. if (isset($_GET['destination'])) {
  68. $destination = drupal_get_destination();
  69. ctools_automodal_admin_ajax_redirect($destination['destination']);
  70. }
  71. else if (isset($form_state['redirect'])) {
  72. ctools_automodal_admin_ajax_redirect($form_state['redirect']);
  73. }
  74. }
  75. function ctools_automodal_admin_ajax_redirect($path) {
  76. ctools_include('ajax');
  77. ctools_add_js('ajax-responder');
  78. $commands[] = ctools_modal_command_dismiss();
  79. $commands[] = ctools_ajax_command_redirect($path);
  80. print ajax_render($commands);
  81. exit();
  82. }