diff --git a/js/modal_forms_comment.js b/js/modal_forms_comment.js index 5cc2a3e..75190ad 100644 --- a/js/modal_forms_comment.js +++ b/js/modal_forms_comment.js @@ -2,10 +2,13 @@ Drupal.behaviors.initModalFormsComment = { attach: function (context, settings) { - $("a[href*='/comment/reply'], a[href*='?q=comment/reply']", context).once('init-modal-forms-comment', function () { - this.href = this.href.replace(/comment\/reply/,'modal_forms/nojs/comment/reply'); + var $comment = $("a[href*='/comment/'], a[href*='?q=comment/']", context).filter(function() { + return this.href.match(/(\/edit|\/reply)/); + }); + $comment.once('init-modal-forms-comment', function () { + this.href = this.href.replace(/comment\//,'modal_forms/nojs/comment/'); }).addClass('ctools-use-modal ctools-modal-modal-popup-medium'); } }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/modal_forms.module b/modal_forms.module index d8fdba3..dd89101 100644 --- a/modal_forms.module +++ b/modal_forms.module @@ -76,6 +76,15 @@ function modal_forms_menu() { 'file' => 'modal_forms.pages.inc', 'type' => MENU_CALLBACK, ); + $items['modal_forms/%ctools_js/comment/%comment/edit'] = array( + 'title' => 'Edit Comment', + 'page callback' => 'modal_forms_comment_edit', + 'page arguments' => array(3, 1), + 'access callback' => 'comment_access', + 'access arguments' => array('edit', 3), + 'file' => 'modal_forms.pages.inc', + 'type' => MENU_CALLBACK, + ); $items['modal_forms/%ctools_js/webform/%node'] = array( 'title' => 'Webform', 'page callback' => 'modal_forms_view_webform', diff --git a/modal_forms.pages.inc b/modal_forms.pages.inc index b9b3817..b3f9bf5 100644 --- a/modal_forms.pages.inc +++ b/modal_forms.pages.inc @@ -245,6 +245,51 @@ function modal_forms_comment_reply($node, $js = NULL, $pid = NULL) { } /** + * A modal edit comment callback. + */ +function modal_forms_comment_edit($comment, $js = NULL) { + $output = array(); + $node = node_load($comment->nid); + + // Fall back if $js is not set. + if (!$js) { + return drupal_get_form('comment_node_' . $node->type . '_form', (object) $comment); + } + + ctools_include('modal'); + ctools_include('ajax'); + + $form_state = array( + 'build_info' => array( + 'args' => array( + (object) $comment, + ), + ), + // 'title' => t('Comment'), + 'ajax' => TRUE, + 're_render' => FALSE, + 'no_redirect' => TRUE, + ); + + $output = drupal_build_form('comment_node_' . $node->type . '_form', $form_state); + + if (!$form_state['executed'] || $form_state['rebuild']) { + $output = ctools_modal_form_render($form_state, $output); + } + else { + // We'll just overwrite the form output if it was successful. + $output = array(); + if (isset($_GET['destination'])) { + $output[] = ctools_ajax_command_redirect($_GET['destination']); + } + else { + $output[] = ctools_ajax_command_reload(); + } + } + print ajax_render($output); +} + +/** * Modal display of the node's webform. * * @param $node